I got this error on the program I am creating. After reading some forums and same problems on the net, I’ve finalyy figured out what the problem is..
The errors appears when I try to get records from the database. The code looks like:
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = “SELECT * FROM ProfileTable ORDER By MemberNo;”;
da = new SqlDataAdapter();
da.SelectCommand = cmd;
ds = new DataSet();
da.Fill(ds, “ProfileTable”);
what I missed out was this line:
cmd.Connection = cn;
Connection was not initialized. OK.
The code now looks like:
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = “SELECT * FROM ProfileTable ORDER By MemberNo;”;
da = new SqlDataAdapter();
da.SelectCommand = cmd;
ds = new DataSet();
da.Fill(ds, “ProfileTable”);
cmd.CommandType = CommandType.Text;
cmd.CommandText = โSELECT * FROM ProfileTable ORDER By MemberNo;โ;
siyet. nosebleed. anong linggawahe to?
LikeLike
Thanx man… I missed the line….
You saved my time…..
LikeLike
thanks it help me.
I was the the same problem
LikeLike