我无法在 C# 中使用“.Union”成功连接两个独立的表并在网格中显示所有列。有人可以告诉我如何解决这个问题吗?
SqlCommand cmd;
SqlCommand cmd1;
SqlCommand cmd2;
string cstr = ConfigurationManager.ConnectionStrings["college"]
.ConnectionString;
using (SqlConnection conn = new SqlConnection(cstr))
{
cmd1 = new SqlCommand("select * from student where studentFirstName LIKE '%'+@studentFirstName+'%'", conn);
cmd1.Parameters.AddWithValue("@studentFirstName", input1);
cmd2 = new SqlCommand("select * from employee where empFirstName LIKE '%'+@empFirstName+'%'", conn);
cmd2.Parameters.AddWithValue("@empFirstName", input2);
cmd = ((cmd1) .Union (cmd2));
}
SqlDataAdapter dAdapt = new SqlDataAdapter(cmd);
DataSet dSet = new DataSet();
dAdapt.Fill(dSet);