Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.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#_.net_Combobox - Fatal编程技术网

C# 连接到两个表

C# 连接到两个表,c#,.net,combobox,C#,.net,Combobox,我已经创建了comboBox并填充了一列,在我从comboBox中选择item之后,我想在textbox中显示其他列,所以我编写了代码来实现这一点,但是如果我想从另一个表中选择列,我的意思是,当我点击comboBox时,我想在textbox中显示两个不同表中的列 这是我的密码: private void comboLname_SelectedIndexChanged(object sender, EventArgs e) { string conn = "Data Source=srv-

我已经创建了comboBox并填充了一列,在我从comboBox中选择item之后,我想在textbox中显示其他列,所以我编写了代码来实现这一点,但是如果我想从另一个表中选择列,我的意思是,当我点击comboBox时,我想在textbox中显示两个不同表中的列 这是我的密码:

private void comboLname_SelectedIndexChanged(object sender, EventArgs e)
{
    string conn = "Data Source=srv-db-02;Initial Catalog=rmsmasterdbtest;Persist Security Info=True;User ID=test;Password=*******";
    string Query = "select * from rmsmasterdbtest.dbo.customer where LastName= '" + comboLname.Text + "' ;";
    SqlConnection Myconn = new SqlConnection(conn);
    SqlCommand cmdDataBase = new SqlCommand(Query, Myconn);
    SqlDataReader Reader;
    try
    {
        Myconn.Open();
        Reader = cmdDataBase.ExecuteReader();
        while (Reader.Read())
        {
            string ID = Reader.GetInt32(Reader.GetOrdinal("ID")).ToString();
            string AccountNuber = Reader.GetString(Reader.GetOrdinal("AccountNumber"));
            //string Time = Reader.GetString(Reader.GetOrdinal("Time"));
            // string Deposit = Reader.GetString(Reader.GetOrdinal("Deposit"));
            string sstatus = Reader.GetString(Reader.GetOrdinal("status"));
            string slastname = Reader.GetString(Reader.GetOrdinal("lastname"));
            txtid.Text = ID;
            txtacnum.Text = AccountNuber;
            //txttime.Text = Time;
            //txtdeposit.Text = Deposit;
            txtstatus.Text = sstatus;
            txtlname.Text = slastname;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        Myconn.Close();
    }
} 

考虑改写你的问题。这很难理解。查找Sql联接的工作原理我试图解释的是,当我在组合框中选择某个项目时,如何在文本框中显示数据,这样我就可以像你在上面的代码中看到的那样,但我仍然希望显示其他表中的更多列。现在,我只显示一个表,它工作正常。下面是我的示例字符串示例:字符串查询=从rmsmasterdbtest.dbo.customer中选择*,其中LastName='+comboLname.Text+';-如何添加另一个表?我希望我对我的英语很清楚,很抱歉,因为它不是我的第一语言