哪位高手能帮我看看这段程序的问题出在哪儿了?
string conStr="Password=506;Persist Security Info=True;User ID=am;Initial Catalog=hostel";
SqlConnection con=new SqlConnection(conStr);
con.Open();
//command
string cmdStr="update admin set username='"+txtAdminUName.Text.Trim()+"',realname='"+txtAdminRName.Text.Trim()+"',pwd='"+txtAdminPwd.Text.Trim()+
"'where username='"+txtAdminUName.Text+"'AND realname='"+txtAdminRName.Text+"'";
SqlCommand cmd=new SqlCommand(cmdStr,con);
cmd.ExecuteNonQuery();
SqlDataAdapter da=new SqlDataAdapter();
// fill dataset
DataSet ds=new DataSet();
da.Fill(ds,"admin");
con.Close();
dgdData.SetDataBinding(ds,"admin");
异常信息是:selectcommand property has not been initialized before calling fill
希望能给出详细一点的答案,小弟是新手谢谢了!如果有在winform窗体中开发,有查询,更新,插入,删除按钮的程序给小弟参考一下,小弟感激不尽!
string conStr="Password=506;Persist Security Info=True;User ID=am;Initial Catalog=hostel";
SqlConnection con=new SqlConnection(conStr);
con.Open();
//command
string cmdStr="update admin set username='"+txtAdminUName.Text.Trim()+"',realname='"+txtAdminRName.Text.Trim()+"',pwd='"+txtAdminPwd.Text.Trim()+
"'where username='"+txtAdminUName.Text+"'AND realname='"+txtAdminRName.Text+"'";
SqlCommand cmd=new SqlCommand(cmdStr,con);
cmd.ExecuteNonQuery();
SqlDataAdapter da=new SqlDataAdapter();
// fill dataset
DataSet ds=new DataSet();
da.Fill(ds,"admin");
con.Close();
dgdData.SetDataBinding(ds,"admin");
异常信息是:selectcommand property has not been initialized before calling fill
希望能给出详细一点的答案,小弟是新手谢谢了!如果有在winform窗体中开发,有查询,更新,插入,删除按钮的程序给小弟参考一下,小弟感激不尽!
da.fill(ds);我也新手,个人意见,不一定正确