我正在为后端有oracle 11g数据库的asp.net网站工作。对于按钮单击,我想执行更新命令。我已经在其他地方执行了其他命令(插入,选择,删除),但是这个命令却给出了无效的标识符。代码如下:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Answer")
{
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button
// from the Rows collection.
GridViewRow row = GridView1.Rows[index];
TextBox TextBox1 = row.FindControl("TextBox1") as TextBox;
string ID = row.Cells[0].Text;
string Date = row.Cells[2].Text;
string answer = TextBox1.Text;
string query = "update \"Review2\" set \"Answer\"='" + answer + "' where \"Cust_id\"=" + ID + " and \"Date\"=to_date('" + Date + "','yyyy-mm-dd hh24:mi:ss')";
SqlDataSource1.UpdateCommand = query;
SqlDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text;
int result = SqlDataSource1.Update();
GridView1.DataBind();
}
}
当我执行此代码时,没有进行更新并且在行:int result = SqlDataSource1.Update(); ,我收到错误,{“ORA-00904:\”ASD \“:无效的标识符\ n”}。任何解决方案?
答案 0 :(得分:2)
您的更新查询语法错误
尝试以下
string query = @"update Review2 set Answer ='" + answer + "' where Cust_id =" + ID + " and Date =to_date('" + Date + "','yyyy-mm-dd hh24:mi:ss')";
注意: - 强烈建议使用参数化查询以避免SQL Injection