string myConnectString ="server=localhost;uid=sa;pwd=;database=forum";
        SqlConnection myConnection = new SqlConnection(myConnectString);
        myConnection.Open();  //连接要先打开        SqlCommand mycommand;
        mycommand.connection = myConnection;
        SqlDataReader rs;

解决方案 »

  1.   

    dim connection as new sqlconnection("server=localhost;uid=sa;pwd=;database=forum")
    dim mycommand as new sqlcommand("...",connection)
    mycommand.connection.open
      

  2.   

    myConnection = new SqlConnection("server=(local);database=oa;uid=oa;pwd=imfine;");
      

  3.   

    按照这样的顺序写:
      SqlConnection myConnection = new SqlConnection(myConnectString);
      string selectCmd = "select id from usermain where userid='"+userid+"' and userpassword='"+password+"'";
      SqlCommand myCommand= new SqlCommand( selectCmd, myConnection);
      myCommand.Connection.Open();
      SqlDataReader sqlDr = myCommand.ExecuteReader();
      while (sqlDr.Read())
         {
          }
      sqlDr.Close();
      myCommand.Connection.Close();