...

View Full Version : Resolved VB.NET Database Adapter SQL WHERE clause issue...



bobleny
04-03-2011, 08:13 PM
I have the following program:


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!

Mike_O
04-04-2011, 05:35 PM
Hey bobleny,

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

Regards,
Mike

bobleny
04-04-2011, 08:36 PM
What!? Why!? Whatever...

Thanks Mike

Mike_O
04-04-2011, 10:00 PM
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'.

bobleny
04-05-2011, 01:49 PM
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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum