![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 張家達 ![]()
![]() |
小弟Update set功能鍵,編輯一筆資料時有問題,卡很久找不出甚麼問題。 請各位前輩幫幫忙 錯誤訊息: 其他資訊: ERROR [07001] [Informix][Informix ODBC Driver]Wrong number of parameters. ERROR [HY000] [Informix][Informix ODBC Driver][Informix]A SERIAL column (no) may not be updated. 程式碼如下: //點擊更新按鈕 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { String updateString = "UPDATE worksheet SET no=?,content=? " +" WHERE no=?"; OdbcCommand cmd = new OdbcCommand(updateString, Conn); da.UpdateCommand= cmd; //da.UpdateCommand.Parameters.Add("@no", OdbcType.Int,0,"no"); da.UpdateCommand.Parameters.Add("@content", OdbcType.VarChar,255,"content"); Conn.Open(); cmd.ExecuteNonQuery(); cmd.Dispose(); Conn.Close(); GridView1.EditIndex = -1; //GVgetData(); }
搜尋相關Tags的文章:
[ ODBC UPDATE SET ] ,
本篇文章發表於2018-03-20 13:51 |
1樓
作者回應
張家達 ![]() |
//點擊更新按鈕
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { String updateString = "UPDATE worksheet SET no=?,content=? " +" WHERE no=?"; OdbcCommand cmd = new OdbcCommand(updateString, Conn); da.UpdateCommand= cmd; //da.UpdateCommand.Parameters.Add("@no", OdbcType.Int,0,"no"); da.UpdateCommand.Parameters.Add("@content", OdbcType.VarChar,255,"content"); Conn.Open(); cmd.ExecuteNonQuery(); cmd.Dispose(); Conn.Close(); GridView1.EditIndex = -1; //GVgetData(); }
本篇文章回覆於2018-03-20 14:25
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
2樓 |
//da.UpdateCommand.Parameters.Add("@no", OdbcType.Int,0,"no");
你把參數註解掉了,SQL參數數量對不起來
本篇文章回覆於2018-03-20 17:05
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
3樓
作者回應
張家達 ![]() |
TO:春天前輩
請問我以下有錯嗎三段有錯嗎?因為我的SQL字串在WHERE no=80 <==指定80列編輯修改可以,但是改成WHERE no=?就會出錯....哀 da.UpdateCommand= new OdbcCommand("UPDATE worksheet SET no=?,projectname=?,categorname=?,recordofwork=?,content=?,hwversion=?,swversion=?,testquantity=?,customer=?" + " WHERE no=?",Conn); da.UpdateCommand.Parameters.Add("@no", OdbcType.Int); da.UpdateCommand.Parameters["@no"].Value = GridView1.Rows[e.RowIndex].Cells[1].Text; [code] //點擊更新按鈕 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //String updateString = "UPDATE worksheet SET content=? "+" WHERE no=?"; //String updateString = "UPDATE worksheet SET projectname=?,categorname=?,recordofwork=?,content=?,hwversion=?,swversion=?,testquantity=?,customer=?" + " WHERE no=?"; //OdbcCommand cmd = new OdbcCommand(updateString, Conn); da.UpdateCommand= new OdbcCommand("UPDATE worksheet SET no=?,projectname=?,categorname=?,recordofwork=?,content=?,hwversion=?,swversion=?,testquantity=?,customer=?" + " WHERE no=?",Conn); da.UpdateCommand.Parameters.Add("@no", OdbcType.Int); //ad.UpdateCommand.Parameters.Add("@no" ,OdbcType.Char, 5, "no").SourceVersion =DataRowVersion.Original; //da.UpdateCommand.Parameters.Add("@workday", OdbcType.DateTime); da.UpdateCommand.Parameters.Add("@projectname", OdbcType.VarChar,30); da.UpdateCommand.Parameters.Add("@categorname", OdbcType.VarChar,30); da.UpdateCommand.Parameters.Add("@recordofwork", OdbcType.Decimal); da.UpdateCommand.Parameters.Add("@content", OdbcType.VarChar,255); da.UpdateCommand.Parameters.Add("@hwversion", OdbcType.VarChar,255); da.UpdateCommand.Parameters.Add("@swversion", OdbcType.VarChar,255); //cmd.Parameters.Add("@belongdepid", SqlDbType.VarChar); da.UpdateCommand.Parameters.Add("@testquantity", OdbcType.Int,0); da.UpdateCommand.Parameters.Add("@customer", OdbcType.VarChar,30); //da.UpdateCommand.Parameters.Add("@demandname", OdbcType.VarChar, 30); da.UpdateCommand.Parameters["@no"].Value = GridView1.Rows[e.RowIndex].Cells[1].Text; //cmd.Parameters["@workday"].Value = GridView1.Rows[e.RowIndex].Cells[1].Text; da.UpdateCommand.Parameters["@projectname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_proj")).SelectedItem.Text; da.UpdateCommand.Parameters["@categorname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_catego")).SelectedItem.Text; da.UpdateCommand.Parameters["@recordofwork"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_recordofwork")).SelectedItem.Value; da.UpdateCommand.Parameters["@content"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_content")).Text; da.UpdateCommand.Parameters["@hwversion"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_swver")).Text; da.UpdateCommand.Parameters["@swversion"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_hwver")).Text; //cmd.Parameters["@belongdepid"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_belon")).SelectedValue; da.UpdateCommand.Parameters["@testquantity"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_testquantity")).Text; da.UpdateCommand.Parameters["@customer"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_customer")).SelectedItem.Text; //da.UpdateCommand.Parameters["@demandname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_demandname")).SelectedItem.Text; Conn.Open(); da.UpdateCommand.ExecuteNonQuery(); cmd.Dispose(); Conn.Close(); GridView1.EditIndex = -1; GVgetData(); }[/code]
本篇文章回覆於2018-03-21 11:17
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
4樓
作者回應
張家達 ![]() |
[code]
//點擊更新按鈕 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //String updateString = "UPDATE worksheet SET content=? "+" WHERE no=?"; //String updateString = "UPDATE worksheet SET projectname=?,categorname=?,recordofwork=?,content=?,hwversion=?,swversion=?,testquantity=?,customer=?" + " WHERE no=?"; //OdbcCommand cmd = new OdbcCommand(updateString, Conn); da.UpdateCommand= new OdbcCommand("UPDATE worksheet SET no=?,projectname=?,categorname=?,recordofwork=?,content=?,hwversion=?,swversion=?,testquantity=?,customer=?" + " WHERE no=?",Conn); da.UpdateCommand.Parameters.Add("@no", OdbcType.Int); //ad.UpdateCommand.Parameters.Add("@no" ,OdbcType.Char, 5, "no").SourceVersion =DataRowVersion.Original; //da.UpdateCommand.Parameters.Add("@workday", OdbcType.DateTime); da.UpdateCommand.Parameters.Add("@projectname", OdbcType.VarChar,30); da.UpdateCommand.Parameters.Add("@categorname", OdbcType.VarChar,30); da.UpdateCommand.Parameters.Add("@recordofwork", OdbcType.Decimal); da.UpdateCommand.Parameters.Add("@content", OdbcType.VarChar,255); da.UpdateCommand.Parameters.Add("@hwversion", OdbcType.VarChar,255); da.UpdateCommand.Parameters.Add("@swversion", OdbcType.VarChar,255); //cmd.Parameters.Add("@belongdepid", SqlDbType.VarChar); da.UpdateCommand.Parameters.Add("@testquantity", OdbcType.Int,0); da.UpdateCommand.Parameters.Add("@customer", OdbcType.VarChar,30); //da.UpdateCommand.Parameters.Add("@demandname", OdbcType.VarChar, 30); da.UpdateCommand.Parameters["@no"].Value = GridView1.Rows[e.RowIndex].Cells[1].Text; //cmd.Parameters["@workday"].Value = GridView1.Rows[e.RowIndex].Cells[1].Text; da.UpdateCommand.Parameters["@projectname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_proj")).SelectedItem.Text; da.UpdateCommand.Parameters["@categorname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_catego")).SelectedItem.Text; da.UpdateCommand.Parameters["@recordofwork"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_recordofwork")).SelectedItem.Value; da.UpdateCommand.Parameters["@content"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_content")).Text; da.UpdateCommand.Parameters["@hwversion"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_swver")).Text; da.UpdateCommand.Parameters["@swversion"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_hwver")).Text; //cmd.Parameters["@belongdepid"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_belon")).SelectedValue; da.UpdateCommand.Parameters["@testquantity"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_testquantity")).Text; da.UpdateCommand.Parameters["@customer"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_customer")).SelectedItem.Text; //da.UpdateCommand.Parameters["@demandname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_demandname")).SelectedItem.Text; Conn.Open(); da.UpdateCommand.ExecuteNonQuery(); cmd.Dispose(); Conn.Close(); GridView1.EditIndex = -1; GVgetData(); } [/code]
本篇文章回覆於2018-03-21 11:18
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
5樓
作者回應
張家達 ![]() |
[code] //點擊更新按鈕
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //String updateString = "UPDATE worksheet SET content=? "+" WHERE no=?"; //String updateString = "UPDATE worksheet SET projectname=?,categorname=?,recordofwork=?,content=?,hwversion=?,swversion=?,testquantity=?,customer=?" + " WHERE no=?"; //OdbcCommand cmd = new OdbcCommand(updateString, Conn); da.UpdateCommand= new OdbcCommand("UPDATE worksheet SET no=?,projectname=?,categorname=?,recordofwork=?,content=?,hwversion=?,swversion=?,testquantity=?,customer=?" + " WHERE no=?",Conn); da.UpdateCommand.Parameters.Add("@no", OdbcType.Int); //ad.UpdateCommand.Parameters.Add("@no" ,OdbcType.Char, 5, "no").SourceVersion =DataRowVersion.Original; //da.UpdateCommand.Parameters.Add("@workday", OdbcType.DateTime); da.UpdateCommand.Parameters.Add("@projectname", OdbcType.VarChar,30); da.UpdateCommand.Parameters.Add("@categorname", OdbcType.VarChar,30); da.UpdateCommand.Parameters.Add("@recordofwork", OdbcType.Decimal); da.UpdateCommand.Parameters.Add("@content", OdbcType.VarChar,255); da.UpdateCommand.Parameters.Add("@hwversion", OdbcType.VarChar,255); da.UpdateCommand.Parameters.Add("@swversion", OdbcType.VarChar,255); //cmd.Parameters.Add("@belongdepid", SqlDbType.VarChar); da.UpdateCommand.Parameters.Add("@testquantity", OdbcType.Int,0); da.UpdateCommand.Parameters.Add("@customer", OdbcType.VarChar,30); //da.UpdateCommand.Parameters.Add("@demandname", OdbcType.VarChar, 30); da.UpdateCommand.Parameters["@no"].Value = GridView1.Rows[e.RowIndex].Cells[1].Text; //cmd.Parameters["@workday"].Value = GridView1.Rows[e.RowIndex].Cells[1].Text; da.UpdateCommand.Parameters["@projectname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_proj")).SelectedItem.Text; da.UpdateCommand.Parameters["@categorname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_catego")).SelectedItem.Text; da.UpdateCommand.Parameters["@recordofwork"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_recordofwork")).SelectedItem.Value; da.UpdateCommand.Parameters["@content"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_content")).Text; da.UpdateCommand.Parameters["@hwversion"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_swver")).Text; da.UpdateCommand.Parameters["@swversion"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_hwver")).Text; //cmd.Parameters["@belongdepid"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_belon")).SelectedValue; da.UpdateCommand.Parameters["@testquantity"].Value = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbx_testquantity")).Text; da.UpdateCommand.Parameters["@customer"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_customer")).SelectedItem.Text; //da.UpdateCommand.Parameters["@demandname"].Value = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("Drop_demandname")).SelectedItem.Text; Conn.Open(); da.UpdateCommand.ExecuteNonQuery(); cmd.Dispose(); Conn.Close(); GridView1.EditIndex = -1; GVgetData(); }[/code]
本篇文章回覆於2018-03-21 11:19
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
6樓
作者回應
張家達 ![]() |
'System.Data.Odbc.OdbcException' 類型的例外狀況發生於 System.Data.dll,但使用者程式碼未加以處理
其他資訊: ERROR [07001] [Informix][Informix ODBC Driver]Wrong number of parameters. ERROR [HY000] [Informix][Informix ODBC Driver][Informix]A SERIAL column (no) may not be updated.
本篇文章回覆於2018-03-21 11:44
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
7樓 |
你no參數另外複製一個試試,不要共用同一個
本篇文章回覆於2018-03-21 14:04
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
8樓
作者回應
張家達 ![]() |
春天大大您好,
如果我no=155 該欄位資料就可以更新~ 這是哪裡出問題阿~QQ
本篇文章回覆於2018-05-25 11:45
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
回覆 |
如要回應,請先登入. |