public void blogDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string updateStr="update userblog set userName="+"\'"+tbName.Value+"\'"+",blog=@blog,remindtime=@remTime,boolRemind=@boolRemind";
SqlCommand myCommand=new SqlCommand(updateStr,myConnection);
myCommand.Parameters.Add(new SqlParameter("@blog",SqlDbType.NVarChar,50));
myCommand.Parameters.Add(new SqlParameter("@remTime",SqlDbType.NVarChar,50));
myCommand.Parameters.Add(new SqlParameter("@boolRemind",SqlDbType.NVarChar,50));
myCommand.Parameters["@blog"].Value=((TextBox)e.Item.Cells[1].Controls[0]).Text;
myCommand.Parameters["@remTime"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
myCommand.Parameters["@boolRemind"].Value=e.Item.Cells[3].Text;
TextBox1.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text;
myCommand.ExecuteNonQuery();
blogDataGrid.EditItemIndex=-1;
BindGrid();
}public void BindGrid()
{
SqlDataAdapter myCommand=new SqlDataAdapter("select"+ "blog,remindTime,boolRemind from userblog where userName="+
"\'"+tbName.Value+"\'",myConnection);
DataSet ds=new DataSet();
myCommand.Fill(ds,"userblog");
blogDataGrid.DataSource=ds.Tables["userblog"].DefaultView;
blogDataGrid.DataBind();
运行过程中未出现任何错误,但是我点击datagrid左边的edit,然后出现textbox,然后我在里面输入新的数据,然后点update,结果重新绑定后datagrid还是显示以前的数据,请问这是怎么回事啊??
{
string updateStr="update userblog set userName="+"\'"+tbName.Value+"\'"+",blog=@blog,remindtime=@remTime,boolRemind=@boolRemind";
SqlCommand myCommand=new SqlCommand(updateStr,myConnection);
myCommand.Parameters.Add(new SqlParameter("@blog",SqlDbType.NVarChar,50));
myCommand.Parameters.Add(new SqlParameter("@remTime",SqlDbType.NVarChar,50));
myCommand.Parameters.Add(new SqlParameter("@boolRemind",SqlDbType.NVarChar,50));
myCommand.Parameters["@blog"].Value=((TextBox)e.Item.Cells[1].Controls[0]).Text;
myCommand.Parameters["@remTime"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
myCommand.Parameters["@boolRemind"].Value=e.Item.Cells[3].Text;
TextBox1.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text;
myCommand.ExecuteNonQuery();
blogDataGrid.EditItemIndex=-1;
BindGrid();
}public void BindGrid()
{
SqlDataAdapter myCommand=new SqlDataAdapter("select"+ "blog,remindTime,boolRemind from userblog where userName="+
"\'"+tbName.Value+"\'",myConnection);
DataSet ds=new DataSet();
myCommand.Fill(ds,"userblog");
blogDataGrid.DataSource=ds.Tables["userblog"].DefaultView;
blogDataGrid.DataBind();
运行过程中未出现任何错误,但是我点击datagrid左边的edit,然后出现textbox,然后我在里面输入新的数据,然后点update,结果重新绑定后datagrid还是显示以前的数据,请问这是怎么回事啊??
结果发现TextBox1还是显示的UPDATE以前的数据,请问这是怎么回事啊??
先答对先抢分啦,呵呵!!
myCommand.Parameters.Add(new SqlParameter("@blog",SqlDbType.NVarChar,50));
myCommand.Parameters.Add(new SqlParameter("@remTime",SqlDbType.NVarChar,50));
myCommand.Parameters.Add(new SqlParameter("@boolRemind",SqlDbType.NVarChar,50));
myCommand.Parameters["@blog"].Value=((TextBox)e.Item.Cells[1].Controls[0]).Text;
myCommand.Parameters["@remTime"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
myCommand.Parameters["@boolRemind"].Value=e.Item.Cells[3].Text;
TextBox1.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text;
string updateStr="update userblog set userName="+"\'"+tbName.Value+"\'"+",blog=@blog,remindtime=@remTime,boolRemind=@boolRemind";
//要把sql语句放到这个后面才给它赋了新值,不然还是原来的数据喔
myCommand.ExecuteNonQuery();
blogDataGrid.EditItemIndex=-1;
BindGrid();
myCommand.ExecuteNonQuery();把updateStr放在后面那myCommand怎么引用它呢??