OleDbConnection myConnection=new OleDbConnection();
myConnection.ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=computerdb";
myConnection.Open();
OleDbCommand myCmd=new OleDbCommand("select U_Name_VC from UserType where U_Password_VC=123456",myConnection);
OleDbDataReader myReader=myCmd.ExecuteReader();
textBox1.Text=myReader.GetString(0);
myReader.Close();
myConnection.Close();显示:
未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中。
为什么啊?
myConnection.ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=computerdb";
myConnection.Open();
OleDbCommand myCmd=new OleDbCommand("select U_Name_VC from UserType where U_Password_VC=123456",myConnection);
OleDbDataReader myReader=myCmd.ExecuteReader();
textBox1.Text=myReader.GetString(0);
myReader.Close();
myConnection.Close();显示:
未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中。
为什么啊?
if(myReader.Read())
{
textBox1.Text=myReader.GetString(0);
}
myReader.Close();
myConnection.Close();
你的连接串少了Data Source=xxxxx这句
conn.open();
sqlcommand cmd = new sqlcommand("select * ....",conn);
SqlReader read = cmd.ExceteReader();
if(read.read())
{
textBox1.Text = read.Getstring(0);
}
read.close();
conn.close();