想从Sql Server 中读出数据调试总是说 SqlDataReader reader= cmd1.ExecuteReader();' ' 附近有语法错误。不知道到底错在哪里?
private void button2_Click(object sender, EventArgs e)
{
string sqlstr3 = "select * from Table_2";
SqlCommand cmd1 = new SqlCommand(sqlstr3, sqlConnection1);
sqlConnection1.Open();
SqlDataReader reader= cmd1.ExecuteReader();
if (reader.Read() == true)
{
textBox1.Text = reader["学号"].ToString();
textBox2.Text = reader["姓名"].ToString();
textBox3.Text = reader["成绩"].ToString();
}
sqlConnection1.Close();
reader.Close();
------解决方案--------------------------------------------------------
"select * from Table_2";
里面你写成了中文空格
应该是
"select * from Table_2";