2

C# で ".Union" を使用して 2 つの独立したテーブルを正常に結合できず、すべての列をグリッドに表示できません。誰かがこれを解決する方法を教えてもらえますか?

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);
4

2 に答える 2