我在sda.Fill(dt)上收到错误;那个Fill:selectcommand.connction属性尚未初始化可能是连接中的问题?
protected void Updatecustomer(object sender, GridViewUpdateEventArgs e)
{
string cstid = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblcustomerid")).Text;
string csnm = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname")).Text;
string cmpn = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcompany")).Text;
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\LENOVO\\Documents\\Visual Studio 2010\\WebSites\\LiveSms\\App_Data\\Sms.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update gridCompany set name=@name,company=@company where cid=@cid;
cmd.Parameters.Add("@cid", SqlDbType.NVarChar).Value = cstid;
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = csnm;
cmd.Parameters.Add("@comnpany", SqlDbType.NVarChar).Value = cmpn;
GridView1.EditIndex = -1;
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}