Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C在条件下连接两个表_C#_Asp.net - Fatal编程技术网

C# C在条件下连接两个表

C# C在条件下连接两个表,c#,asp.net,C#,Asp.net,在使用下面的代码之后,我在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(); SqlComman

在使用下面的代码之后,我在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();

正如Soner所说,您的信息是有限的,但是如果您的查询出现异常,请尝试在查询之前留出一个空间,并一次仅从一个表中进行选择:

SqlCommand cmd = new SqlCommand("select * from tblOutageTransactionDetails where  ToolsOutageID = " + x + " and toolid = " + y, con);

您的代码中有任何异常或错误消息吗?您是否先在管理工作室中尝试了查询?有效吗?如果没有,您会收到什么错误消息?这些列的类型是什么?当您询问时,请更加具体;看起来很可疑。。。尝试GridView1.DataSource=ds.Tables[0];相反,没有错误,它在gridview中为我提供了一些垃圾输出,区分大小写初始化表名…..请不要从2个表中选择*,尤其是在进行笛卡尔联接时。只选择您绝对需要的行,这样您就可以限制数据库和客户端之间的通信量。此外,除了上面的注释外,您的查询前和查询中必须有一个空格+x+和