English 中文(简体)
为什么这种问话给我一个例外?
原标题:Why does this query give me an exception?
  • 时间:2010-10-05 13:59:51
  •  标签:
  • asp.net
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 + ")"

这种不平衡的争问给我一个例外,告诉我,“......”附近有一处错误。 错误是什么。 请更正。

问题回答

我纯粹是猜测,但应该是年? 未选定指数?

我不理解为什么你想要把参数替代混在一起。

将所有五栏列为参数,并确定相应的数值。

"INSERT INTO TEAM_FUNDS_DETAILS " +
"(COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR) " +
"VALUES(? , ?, ?,?, ?)"

你们必须确定参数值(有问题标记的数值)。 在VB中就是一个类似的例子。 NET:

  Make a Command f或 this connection
  and this transaction.
Dim cmd As New OleDb.OleDbCommand( _
    "SELECT * FROM People WHERE FirstName=? AND " & _
        "LastName=?", _
    connUsers)

  Create parameters f或 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 + ")"

ddl Month.S selectedItem.Value





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签