IListSource不包含任何数据源
我碰到一个奇怪的问题:我做了一段更新,数据库里的确也更新了,可就是应用程序报错,按道理如果我代码写错了,数据库是不会更新的,可现在它的确更新了,这个问题让我很郁闷,谁能帮帮我?
(我更新的代码):
private void dg1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strName;
strName = dg1.DataKeys[(int)e.Item.ItemIndex].ToString();
TextBox txtName = (TextBox)e.Item.FindControl("txtName");
DropDownList dropCity = (DropDownList)e.Item.FindControl("dropCity");
//string txtCity = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text;
TextBox txtAddress = (TextBox)e.Item.FindControl("txtAddress");
TextBox txtPost = (TextBox)e.Item.FindControl("txtPost");
TextBox txtPhone = (TextBox)e.Item.FindControl("txtPhone");
string dsn;
dsn = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
SqlConnection conn = new SqlConnection(dsn);
SqlDataAdapter da = new SqlDataAdapter("update1_sp",conn);
SqlCommand comm = da.SelectCommand;
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@Name",SqlDbType.NVarChar).Value = txtName.Text;
comm.Parameters.Add("@City",SqlDbType.NVarChar).Value = dropCity.SelectedValue;
comm.Parameters.Add("@Address",SqlDbType.Text).Value = txtAddress.Text;
comm.Parameters.Add("@Post",SqlDbType.VarChar).Value = txtPost.Text;
comm.Parameters.Add("@Phone",SqlDbType.VarChar).Value = txtPhone.Text;
comm.Parameters.Add("@ID",SqlDbType.Int).Value = strName;
//comm.Parameters.Add("@NickName",SqlDbType.NVarChar).Value = lblGreeting1.Text;
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
dg1.DataSource = ds;
dg1.DataBind();
conn.Close();
dg1.EditItemIndex = -1;
select1();
}
(我的存储过程):
CREATE proc update1_sp
@Name nvarchar(4),
@City nvarchar(12),
@Address text,
@Post varchar(6),
@Phone varchar(13),
@ID int
--@NickName nvarchar(50)
as
update Product set Name=@Name,Address=@Address,Post=@Post,Phone=@Phone
where ID=@ID
GO
???