Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder bobleny's Avatar
    Join Date
    May 2007
    Posts
    258
    Thanks
    3
    Thanked 11 Times in 11 Posts

    VB.NET Database Adapter SQL WHERE clause issue...

    I have the following program:
    Code:
    Dim SetData As DataSet	' Stores the information
    Dim Connection As New OleDb.OleDbConnection
    Dim Adapter As OleDb.OleDbDataAdapter
    
    ' Connect to  the database
    Connection.ConnectionString = "PROVIDER = Microsoft.Jet.OLEDB.4.0; Data Source = ./App_Data/VB.mdb"
    Connection.Open() ' Open the database
    ' Get the information from the database
    Adapter = New OleDb.OleDbDataAdapter("SELECT * FROM [Customer Query] WHERE [Name] = [George]", Connection)
    SetData = New DataSet
    Adapter.Fill(SetData, "Query")	' Store the database information in DataSet
    Connection.Close()	' Close the connection
    The problem appears to be with the where clause of the SQL query. When I remove the where clause, the program works fine. However, with the where clause I get this error:
    No value given for one or more required parameters.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

    Source Error:
    Line 43: Adapter = New OleDb.OleDbDataAdapter("SELECT * FROM [Customer Query] WHERE [Name] = [George]", Connection)
    Line 44: SetData = New DataSet
    Line 45: Adapter.Fill(SetData, "Query") ' Store the database information in DataSet
    Line 46: Connection.Close() ' Close the connection
    Line 47:

    Source File: C:\Documents and Settings\Bob\Desktop\DatabaseRecords\Default.aspx Line: 45

    Stack Trace:
    [OleDbException (0x80040e10): No value given for one or more required parameters.]
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1003520
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
    System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
    System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
    System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
    System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +116
    System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +4
    System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
    ASP.default_aspx.Selection_Change() in C:\Documents and Settings\Bob\Desktop\DatabaseRecords\Default.aspx:45
    ASP.default_aspx._Lambda$__2(Object a0, EventArgs a1) in C:\Documents and Settings\Bob\Desktop\DatabaseRecords\Default.aspx:89
    System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +111
    System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() +134
    System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent( ) +10
    System.Web.UI.Page.RaiseChangedEvents() +165
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1485
    When I use the where clause in a standard VB.NET windows application I have no problem, so I don't know what to do.

    Any ideas?

    Thanks!
    Last edited by bobleny; 04-05-2011 at 01:49 PM.
    --www.firemelt.net--
    * No good deed goes unpunished.
    * Cheer up, the worst has yet to come...

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Hey bobleny,

    I'm not 100% sure about this one, but try changing [George] to 'George'.

    Regards,
    Mike

  • #3
    Regular Coder bobleny's Avatar
    Join Date
    May 2007
    Posts
    258
    Thanks
    3
    Thanked 11 Times in 11 Posts
    What!? Why!? Whatever...

    Thanks Mike
    --www.firemelt.net--
    * No good deed goes unpunished.
    * Cheer up, the worst has yet to come...

  • #4
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    What!? Why!? Whatever...

    Thanks Mike

    ....??? What exactly is the issue here? And this wouldn't be the first time that when I try to help you, that I get that kind of a response in return. If I misinterpreted your tone, then please forgive me.

    Anyway, like I was saying, inside your select statement, try changing [George] to 'George'.

  • #5
    Regular Coder bobleny's Avatar
    Join Date
    May 2007
    Posts
    258
    Thanks
    3
    Thanked 11 Times in 11 Posts
    No, I'm sorry. I can see how that could be misconstrued. The "Thanks Mike" was sincere. The "What!? Why!? Whatever..." was in response to the stupid SQL issue. I've done lots of SQL and never used square brackets, I've always used single quotes or none at all. For this APS.NET project however, if I didn't use them I got SQL errors. Then all of the sudden, I get the aforementioned error, in which I spend a couple hours trying to figure out, and it turns out I needed to use single quotes...
    --www.firemelt.net--
    * No good deed goes unpunished.
    * Cheer up, the worst has yet to come...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •