string intChinese = e.Item.Cells[2].Text;
string intMath = e.Item.Cells[3].Text;
string intEnglish = e.Item.Cells[4].Text;
string intPhysical = e.Item.Cells[5].Text;
//更新数据库中的数据
string strUpdate = "Update Score Set Chinese="+intChinese+" Where ID="+strID+"";
OleDbCommand MyComm = new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();执行是老是说update语句错误啊。请大家看看。谢谢
string intMath = e.Item.Cells[3].Text;
string intEnglish = e.Item.Cells[4].Text;
string intPhysical = e.Item.Cells[5].Text;
//更新数据库中的数据
string strUpdate = "Update Score Set Chinese="+intChinese+" Where ID="+strID+"";
OleDbCommand MyComm = new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();执行是老是说update语句错误啊。请大家看看。谢谢
收分
<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<Script Language="C#" Runat="Server">
OleDbConnection MyConn;
public string mystring;
public void Page_Load(Object src,EventArgs e)
{
//连接语句
string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(".")+"..\\DataBase\\db1.mdb;";
MyConn = new OleDbConnection(MyConnString);
MyConn.Open(); if(!Page.IsPostBack)
{
BindGrid();
}
}
ICollection CreateTable()
{
string strSel = "select * from Score";
DataSet ds = new DataSet(); OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,"Score"); return ds.Tables["Score"].DefaultView;
}
public void BindGrid()
{
score.DataSource = CreateTable();
score.DataBind();
}//处理Edit命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}//处理Cancel命令
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemIndex = -1;
BindGrid();
}//处理Update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息 string strID = e.Item.Cells[1].Text;
string intChinese = e.Item.Cells[2].Text;
string intMath = e.Item.Cells[3].Text;
string intEnglish = e.Item.Cells[4].Text;
string intPhysical = e.Item.Cells[5].Text;
mystring=strID;
//更新数据库中的数据
string strUpdate = "Update Score Set Chinese='"+intChinese+"' Where ID="+strID;
OleDbCommand MyComm = new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();
score.EditItemIndex = -1;
BindGrid();}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<center>
<b>演示EditCommandColumn *<% =mystring %>*</b>
<asp:DataGrid id="score" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False"
OnEditCommand="DataGrid_EditCommand"
OnUpdateCommand="DataGrid_UpdateCommand"
OnCancelCommand="DataGrid_CancelCommand"
>
<Columns>
<asp:EditCommandColumn HeaderText="操作区"
EditText="编辑"
UpdateText="更新"
CancelText="取消"
ButtonType="PushButton"
/>
<asp:BoundColumn HeaderText="ID" DataField="ID" ReadOnly="True" />
<asp:BoundColumn HeaderText="语文" DataField="Chinese" />
<asp:BoundColumn HeaderText="数学" DataField="Math" />
<asp:BoundColumn HeaderText="英语" DataField="English" />
<asp:BoundColumn HeaderText="物理" DataField="Physics"/>
</Columns>
</asp:DataGrid>
</center></form>
</body>
</html>数据库定义为:
字段名称 数据类型
ID 自动编号
Name 文本
Class 文本
Chinese 文本
Math 文本
English 文本
Physics 文本
History 文本还是希望大家能帮忙解决一下。