ERROR ExecuteReader not initialized
Hello:
I am trying to read a record and getting an error: {"ExecuteReader: Connection property has not been initialized."}. Can someone help?
I have used the same connection inn other places and it does connect. I have the select statement displayed and it looks correct.
DBSQLSelect = "SELECT "
+ " [SEQNO]"
+ " ,[Name]"
+ " ,[Address_1]"
+ " ,[Address_2]"
+ " FROM"
+ " [" + Program_ID + "]"
+ " WHERE"
+ " [Company_ID] = '" + textBoxCompany_ID.Text + "'"
;
//
string DBConnection =
@"Server=" + Program.ProgramDBServer + ";"
+ "Database=" + Program.ProgramDBDatabase + ";"
+ "User ID=" + Program.ProgramDBLogin_ID + ";"
+ "Password=" + Program.ProgramDBPassword + ";";
//
MessageBox.Show("DBConnection=" + DBConnection);
MessageBox.Show("DBSQLSelect=" + DBSQLSelect);
//
SqlDataReader ReadRecord = null;
//
SqlConnection SQLConnect = new SqlConnection(DBConnection);
//
SqlCommand SQLCommand = new SqlCommand(DBSQLSelect);
//
SQLConnect.Open();
SQLConnect.GetSchema();
//
ReadRecord = SQLCommand.ExecuteReader(); //<<< {"ExecuteReader: Connection property has not been initialized."}
//
textBoxName.Text = (string) ReadRecord["Name"];
textBoxName.Text = ReadRecord.GetString(ReadRecord.GetOrdinal("Name"));