小弟写了一个连接数据库的简单语句
连接时出现异常,出现异常的语句如下:System.Data.OleDb.OleDbDataReader reader = comm.ExecuteReader();
系统提示说:至少一个变量没赋值,为处理OleDbException。
应该怎样改啊?
谢谢了

解决方案 »

  1.   

    100%是你的SQL语句错误。可能是没有写表名吧。
    昨天我还遇到过,仔细看看你的SQL语句
      

  2.   

    try
    {
    SqlConnection conn = new SqlConnection("Server=(local);uid=sa;pwd=;database=pubs");
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = conn;
    cmd.CommandType = CommandTpye.Text;
    cmd.CommandText = "select * from b";
    cmd.Connection.Open();
    cmd.ExecuteNonQuery();
    }
    catch(Exception err)
    {
     throw err;
    }
    finally
    {
      cmd.Connection.Close();
      conn.Close();
    }"Server=(local);uid=sa;pwd=;database=pubs"  连接字符串,自己按需要改一下
    这是SQLSERVER的连接,改一下就行了。
      

  3.   

    全部的语句如下:
     //建立连接
                System.Data.OleDb.OleDbConnection conn =
                    new System.Data.OleDb.OleDbConnection();
                //设置连接
                conn.ConnectionString =
                    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Customer.mdb";
                //打开连接
                conn.Open();
                //设置查询语句
                String strQuery = "SELECT * From TelTable WHERE Name='" + this.textBox1.Text + "'";
                //创建命令
                System.Data.OleDb.OleDbCommand comm =
                    new System.Data.OleDb.OleDbCommand(strQuery, conn);
              
                //执行
                System.Data.OleDb.OleDbDataReader reader = comm.ExecuteReader();            //读取
                if (reader.Read())
                    this.label2.Text = reader.GetValue(2).ToString();
                else
                    this.label2.Text = "";
                //关闭
                reader.Close();
                conn.Close();
    那位大哥看看帮我?