我试图连接两列,但出了点问题.... 我的输出没有显示。
String Query = " SELECT pa_forename , pa_surname FROM [ICPS].[dbo].[parking_attendants] order by pa_forename ";
SqlConnection conDataBase = new SqlConnection(conString);
SqlCommand cmdDataBase = new SqlCommand(Query, conDataBase);
SqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
string pa_forename = myReader["pa_forename " +"," + "pa_surname"].ToString();
comboBox1.Items.Add(pa_forename);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
答案 0 :(得分:7)
替换
string pa_forename = myReader["pa_forename " +"," + "pa_surname"].ToString();
带
string pa_forename = myReader["pa_forename"] +"," + myReader["pa_surname"];
答案 1 :(得分:0)
你做错了,
string pa_forename = myReader["pa_forename " +"," + "pa_surname"].ToString();
您无法同时从DataReader
获取两列。用这样的代码替换你的代码。上面的代码将尝试查找不存在的列。
string pa_forename = myReader["pa_forename"] +"," + myReader["pa_surname"];