string updateIncomeData = @"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , ?, ?,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
这个参数化查询给了我一个异常,告诉我“?”附近有错误。什么是错误。请更正。
答案 0 :(得分:1)
我纯粹猜测,但它应该是year.selecteditem?没选择指数?
答案 1 :(得分:0)
我不明白你为什么要混淆参数替换。
将所有五列指定为参数并以此方式设置值。
"INSERT INTO TEAM_FUNDS_DETAILS " +
"(COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR) " +
"VALUES(? , ?, ?,?, ?)"
答案 2 :(得分:0)
您必须设置参数化值(带问号的值)。这是VB.NET中的一个类似示例:
' Make a Command for this connection
' and this transaction.
Dim cmd As New OleDb.OleDbCommand( _
"SELECT * FROM People WHERE FirstName=? AND " & _
"LastName=?", _
connUsers)
' Create parameters for the query.
cmd.Parameters.Add(New _
OleDb.OleDbParameter("FirstName", first_name))
cmd.Parameters.Add(New OleDb.OleDbParameter("LastName", _
last_name))
如果您不想使用参数化查询,只需将问号替换为默认值,或将变量替换为值:
string updateIncomeData = @"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , '', 0,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
或
string updateIncomeData = @"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , '" + myComponentName + "', " + myComponentAmount,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
答案 3 :(得分:0)
ddlMonth.SelectedItem.Value