【发布时间】:2014-11-06 12:41:25
【问题描述】:
protected void UpdateCustomer(object sender, GridViewUpdateEventArgs e)
{
string CustomerID = ((Label)GridView1.Rows[e.RowIndex]
.FindControl("lblCustomerID")).Text;
string Name = ((TextBox)GridView1.Rows[e.RowIndex]
.FindControl("txtContactName")).Text;
string Company = ((TextBox)GridView1.Rows[e.RowIndex]
.FindControl("txtCompany")).Text;
MySqlConnection con = new MySqlConnection();
string Connection = "Server=localhost;" +
"DATABASE=northwind2007;" + "username=;" +
"PASSWORD=;";
con.ConnectionString = Connection;
MySqlCommand cmd = new MySqlCommand();
cmd = new MySqlCommand(cmd.CommandText, con);
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update Customers set FirstName=@ContactName," +
"Company=@CompanyName where ID=@CustomerID;" + "select ID,FirstName,Company from Customers";
cmd.Parameters.AddWithValue("@CustomerID", MySqlDbType.VarChar).Value = CustomerID;
cmd.Parameters.AddWithValue("@ContactName", MySqlDbType.VarChar).Value = Name;
cmd.Parameters.AddWithValue("@CompanyName", MySqlDbType.VarChar).Value = Company;
GridView1.EditIndex = -1;
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
我已经尝试了所有方法,但现在解决了,每次我尝试从我的网格更新记录时都会引发此错误。
【问题讨论】:
-
究竟在哪一行?您的问题不清楚。
-
@SonerGönül at da.Fill(dt);
-
@RowlandShaw 不,我只是把它命名为那个。
标签: c# mysql .net ajax webgrid