急!!!菜鸟求asp.net 关于查询实现详细代码
数据库是sql2000,求高手帮帮忙我需要用到的表是 Employees ,Bumen ,Employees.BumenID=Bumen.BumenID
我想通过三个条件来实现查询 1、部门 2、工号 3、姓名
结果是显示Employees的一行
不知道下面的查询语句对不对
"select Employees.EmployeeID,Employees.EmployeePWD,Employees.EmployeeName,Employees.NowState,Employees.DengjiID,Employees.RoleID,Employees.BumenID,Employees.Sex,Employees.Address,Employees.Tell,Employees.Email from Bumen,Employees where Bumen.BumenID=Employees.BumenID";
求各位大侠帮帮忙!一定要给我个详细代码,要不然我不懂改啊!!! --------------------编程问答-------------------- select E.部门,E.工号,E.姓名 from Employees as E,Bumen where Bumen.BumenID=E.ID
和你写的差不多吗。
如果可以,简易创建视图,方便查看和后续使用。 --------------------编程问答-------------------- select Employees .*,Bumen.* from Employees inner join Bumen on Bumen.BumenID=E.ID
--------------------编程问答--------------------
lz说明白点 你是想通过1部门,2工号3,姓名这三个条件来查询吗? 想查询出什么结果? --------------------编程问答-------------------- select e.*,b.部门名称 from Employees as e
left join Bumen b on b.BumenID=e.BumenID
where e.工号='工号' and b.部门名称='部门名称' and e.EmployeeName like '%姓名%' --------------------编程问答-------------------- 我要的不只是查询语句
是像下面的详细代码
各位帮帮忙啊
★★★★★Default.aspx.cs代码文件★★★★★
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string sqlstr = "Data Source=(local);Database=Northwind;Uid=sa;Pwd=";
SqlConnection sqlconn;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.bind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
string str = "select * from Region where RegionID='" + TextBox1.Text.Trim() + "'";
sqlconn = new SqlConnection(sqlstr);
sqlconn.Open();
SqlCommand sqlcom = new SqlCommand(str,sqlconn);
int result = Convert.ToInt32(sqlcom.ExecuteScalar());
if (result > 0)
{
SqlDataAdapter myda = new SqlDataAdapter(str, sqlconn);
DataSet myds = new DataSet();
myda.Fill(myds);
GridView1.DataSource = myds;
GridView1.DataBind();
sqlconn.Close();
}
else
Response.Write("<script>alert('没有相关记录')</script>");
}
else
this.bind();
}
public void bind()
{
string str = "select * from Region";
sqlconn = new SqlConnection(sqlstr);
sqlconn.Open();
SqlDataAdapter myda = new SqlDataAdapter(str, sqlconn);
DataSet myds = new DataSet();
myda.Fill(myds);
GridView1.DataSource = myds;
GridView1.DataBind();
sqlconn.Close();
}
}
--------------------编程问答-------------------- 回复3楼的,是的,查询的结果是显示
EmployeeID,EmployeePWD,EmployeeName,NowState,DengjiID,RoleID,BumenID,Sex,Address,Tell,Email
也就是Employees表的全部的列 --------------------编程问答--------------------
那这个就可以满足lz的需要了 只需把*换成lz想要的字段就可以了
补充:.NET技术 , ASP.NET