A B C D E五个表,name 为每个表都有的项,表示相同内容,且都是主键,每个表都是对于name有唯一记录。
现在要根据查询条件,例如c.mm="小王' and d.time="2006-3-3",联查五个表中的任意几项,并且动态绑定到一个datagrid上,查询条件和需要显示的项都是动态的,写在Label中。
请大家帮忙,告诉我如何实现,代码怎么写,我在网上找了些资料,可是加到我的程序里总是报错,解决不了。
先谢谢了
现在要根据查询条件,例如c.mm="小王' and d.time="2006-3-3",联查五个表中的任意几项,并且动态绑定到一个datagrid上,查询条件和需要显示的项都是动态的,写在Label中。
请大家帮忙,告诉我如何实现,代码怎么写,我在网上找了些资料,可是加到我的程序里总是报错,解决不了。
先谢谢了
解决方案 »
- asp.net中怎样实现不同登录用户在页面能显示自己的信息
- xmlhttp.status一直为404 怎么回事
- asp.net自动建立文件夹
- 关于DB.CS~
- 如何从GridView中导出数据?(GridView不是直接拖放工具栏的)
- 想点击增加后.弹出一个比较小的对话窗口.而不是弹出一个链接页面
- 怎样在文本框里同时上传文字和插入图片
- 无效的 URI: 无法分析主机名。
- public MulLanguage():base(HtmlTextWriterTag.Div){}这句代码在VB中如何写?
- vs2017加载一个ASP.NET Core Web 项目运行出错,闪退,出现下面信息,怎么解决?
- 这里的高手都去那里了呢?为什么没人能够帮帮我呢?
- 急~~~~iframe 获取父页面的URL 父页面为静态~不用JavaScript
join c on c.id=a.id
Label2.Text=Request.QueryString["var2"];//查询条件
string strConnection=System.Configuration .ConfigurationSettings.AppSettings ["Connect"];
SqlConnection con=new SqlConnection (strConnection);
SqlDataAdapter sda=new SqlDataAdapter();
SqlCommand sc=con.CreateCommand();
sda.SelectCommand=sc;
//DataTable newtable = ds1.Tables.Add("newtable");
con.Open();
if(Label2.Text!="")
sc.CommandText="SELECT "+Label1.Text+" FROM A INNER JOIN B ON A.name = B.name INNER JOIN C ON A.name = C.name INNER JOIN E ON A.name = E.name INNER JOIN D ON A.name = D.name where "+Label2.Text;
else
sc.CommandText="SELECT "+Label1.Text+" FROM A INNER JOIN B ON A.name = B.name INNER JOIN C ON A.name = C.name INNER JOIN E ON A.name = E.name INNER JOIN D ON A.name = D.name";
DataGrid1.DataSource=ds1.Tables["newtable"];
DataGrid1.DataMember=("newtable");
sda.Fill(ds1);
this.DataGrid1.DataBind();
con.Close();总是报错,郁闷阿
Label2.text="A.ss=oo or B.ww=qq"
Label2.Text=Request.QueryString["var2"];//cx
string strConnection=System.Configuration .ConfigurationSettings.AppSettings ["Connect"];
SqlConnection con=new SqlConnection (strConnection);
SqlDataAdapter sda=new SqlDataAdapter();
SqlCommand sc=con.CreateCommand();
con.Open();
if(Label2.Text!="")
sc.CommandText="SELECT "+Label1.Text+" FROM (codecharacter JOIN codeintro ON codecharacter.codename = codeintro.codename JOIN messagecharacter ON codecharacter.codename = messagecharacter.codename JOIN research ON codecharacter.codename = research.codename JOIN spy_control ON codecharacter.codename = spy_control.codename) where "+Label2.Text;
else
sc.CommandText="SELECT "+Label1.Text+" FROM (codecharacter JOIN codeintro ON codecharacter.codename = codeintro.codename JOIN messagecharacter ON codecharacter.codename = messagecharacter.codename JOIN research ON codecharacter.codename = research.codename JOIN spy_control ON codecharacter.codename = spy_control.codename)";
DataGrid1.DataSource=ds1.Tables["codecharacter"];
DataGrid1.DataMember=("codecharacter");
sda.SelectCommand=sc;
sda.Fill(ds1,"codecharacter");
this.DataGrid1.DataBind();
con.Close();
调整了一下,现在抱错:
未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
DataGrid1.DataMember=("newtable");
sda.Fill(ds1);
是不是顺序搞错了哟?
DataGrid1.DataSource=ds1.Tables["newtable"].DefaultView;
this.DataGrid1.DataBind();
太好了,非常感谢