Connecting to SQL !!!
-
Hey guys, whats up ? I want to connect to SQL in ASP.NET In my main form I have this code: I have added a SQLDatasource for my connection string !
MyConn.ConnectionString = SqlDataSource1.ConnectionString; MyConn.Open(); MyCmd.CommandText = "SELECT UserName from UserT where UserName = " + UserName_tb.Text;
string CheckName = (string)MyCmd.ExecuteScalar();
in this line I get this error ! ExecuteScalar: Connection property has not been initialized. -
Hey guys, whats up ? I want to connect to SQL in ASP.NET In my main form I have this code: I have added a SQLDatasource for my connection string !
MyConn.ConnectionString = SqlDataSource1.ConnectionString; MyConn.Open(); MyCmd.CommandText = "SELECT UserName from UserT where UserName = " + UserName_tb.Text;
string CheckName = (string)MyCmd.ExecuteScalar();
in this line I get this error ! ExecuteScalar: Connection property has not been initialized. -
The error is self explanatory. You havent set the connection property for "MyCmd" i.e. sqlCommand. Not very sure about VB syntax, but you need to do something like. "MyCmd.Connection = MyConn " It shud solve problem.