大家来给瞅瞅代码,怎么修改不了,输入数据点修改没反应,感谢
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlcn = new SqlConnection(@"Data Source=.;Initial Catalog=zsgc;Integrated Security=SSPI;");
sqlcn.Open();
SqlCommand sqlcm = new SqlCommand("select * from student",sqlcn);
SqlCommand myUpdateCommand = new SqlCommand();
myUpdateCommand.CommandText = @"Update student set name=@name where id=@id";
myUpdateCommand.Connection = sqlcn;
myUpdateCommand.Parameters.Add(new SqlParameter("@id",SqlDbType.Text,20,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"id",System.Data.DataRowVersion.Original,null));
myUpdateCommand.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,20,"name"));
SqlDataAdapter sqlda = new SqlDataAdapter();
sqlda.SelectCommand = sqlcm;
sqlda.UpdateCommand = myUpdateCommand;
DataSet ds = new DataSet();
sqlda.Fill(ds,"student");
DataTable myTable=ds.Tables["student"];
foreach (DataRow myRow in myTable.Rows)
{
if (myRow["id"].ToString() == TextBox1.Text.Trim())
{
myRow["name"] = TextBox2.Text.Trim();
Response.Write("ok");
myRow.Delete();
sqlda.Update(ds,"student");
Response.Write("ok!");
sqlcn.Close();
}
}
}