public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
string strName = e.Item.Cells[1].Text;
int intChinese = Int32.Parse(((TextBox)e.Item.Cells[2].Controls[0]).Text);
int intMath = Int32.Parse(((TextBox)e.Item.Cells[3].Controls[0]).Text);
int intEnglish = Int32.Parse(((TextBox)e.Item.Cells[4].Controls[0]).Text);
         ///string newString=怎么写??? //更新数据库中的数据
string strUpdate = "Update Score Set Chinese="+intChinese+",Math="+intMath+",English="+intEnglish+" Where Name='"+strName+"'";
         ///string strUpdate = "Update Score Set Chinese="+intChinese+",Math="+intMath+",English="+intEnglish+",String='"+newString+"' Where Name='"+strName+"'";这样写对吗???? OleDbCommand MyComm = new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();

score.EditItemIndex = -1;
BindGrid();
}
偶想编辑一个文本类型的字段,该怎么写C#代码和SQL语句呢?
数据库是ACCESS~

解决方案 »

  1.   

    ///string strUpdate = "Update Score Set Chinese="+intChinese+",Math="+intMath+",English="+intEnglish+",String='"+newString+"' Where Name='"+strName+"'";这样写对吗????
    ------------------------------------------------------------------------------------
    不对,应该这样写:
    string strUpdate = "Update Score Set Chinese="+"'"+intChinese+"'"+",Math="+"'"+intMath+"'"+",English="+"'"+intEnglish+"'"+",String="+newString+" Where Name="+strName;
      

  2.   

    先更新DataSet再更新数据库... 表像ASP那样写程序
      

  3.   

    呵呵,后面的 Where Name="+strName;的确可以简化 这点看例子代码的时候偶没有注意但关键是偶想增加的编辑文本字段的那句C#语句和涉及到那个字段的SQL写法原来的例子是可以完整运行的~
    增加修改一些偶想达到编辑ACCSESS数据库文本字段的功能。