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 中。
为什么啊?

解决方案 »

  1.   

    OleDbDataReader myReader=myCmd.ExecuteReader();
    if(myReader.Read())
    {
    textBox1.Text=myReader.GetString(0);
    }
    myReader.Close();
    myConnection.Close();
      

  2.   

    Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=127.0.0.1
    你的连接串少了Data Source=xxxxx这句
      

  3.   

    sqlserver请用sqlclient类.sqlconnection conn = new sqlconnection("data source=(local);user id=sa;pwd=sa;database=NorthWind");
    conn.open();
    sqlcommand cmd = new sqlcommand("select * ....",conn);
    SqlReader read = cmd.ExceteReader();
    if(read.read())
    {
       textBox1.Text = read.Getstring(0);
    }
    read.close();
    conn.close();