日期:2014-05-18  浏览次数:20828 次

c# 用Lable显示读取到的SQL数据
string selectUserID = "select UserID from dl where ksh='" + comboBox5.Text + "'";
 SqlConnection conn = new SqlConnection(strconn);
 SqlCommand nselectUserID = new SqlCommand(selectUserID, conn);
 conn.Open();
 SqlDataReader ksh=nselectUserID.ExecuteReader();
 label3.Text = ksh.ToString();
 conn.Close();
为什么显示出来的不对,显示的是“System.Data.SqlClient.SqlDataReade”。



------解决方案--------------------
if(ksh.Read())
{
label3.Text = reader["UserID"].ToString();
}

------解决方案--------------------
string selectUserID = "select UserID from dl where ksh='" + comboBox5.Text + "'"; 
SqlConnection conn = new SqlConnection(strconn); 
SqlCommand nselectUserID = new SqlCommand(selectUserID, conn); 
conn.Open(); 
SqlDataReader ksh=nselectUserID.ExecuteReader(); 
string strValue = "";
while(ksh.Read())
{
strValue = strValue + ksh[0].ToString() + " ";
}
label3.Text = strValue;
conn.Close();