c#在条件下连接两个表
本文关键字:两个 条件下 连接 | 更新日期: 2023-09-27 18:01:46
使用下面的代码后,我没有得到gridview上的任何输出,我没有正确地连接表
int x = Convert.ToInt32(this.Request.QueryString["outageID"]);
int y = Convert.ToInt32(this.Request.QueryString["toolid"]);
SqlConnection con = new SqlConnection("xyz");//connection name
con.Open();
SqlCommand cmd = new SqlCommand("select * from tblOutageTransactionDetails,tbltools where ToolsOutageID = " + x + "and toolid = " + y, con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables;
GridView1.DataBind();
con.Close();
As Soner正确地说您的信息是有限的,但是,如果您在查询上遇到异常,请尝试在and
之前留下一个空间,并一次只从1个表中进行选择:
SqlCommand cmd = new SqlCommand("select * from tblOutageTransactionDetails where ToolsOutageID = " + x + " and toolid = " + y, con);