Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OleDbCommands with Parameters
Message
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00702958
Message ID:
00703352
Views:
20
I was able to duplicate your problem. The updated OleDb provider, soon to be released, will fix this issue. Until then, you will need to not use parameters in your Select statement and send the value itself inside of the statement instead, like the following:
Dim strSelect As [String] = "SELECT * FROM ORDITEMS WHERE LINE_NO=1"
>Thanks, Cathi; this illustrates the problem I am having.
>
>When I run your code sample in a Visual Studio .NET VB Windows Form, I get the following error message at the line where oSelectCommand.ExecuteReader() is called:
>
>"An unhandled exception of type 'System.NullReferenceException' occurred in system.data.dll
>
>Additional information: Object reference not set to an instance of an object."
>
>
>Any idea why this is happening?
>
>>Here is some sample code that uses the TestData DBC in VFP7:
>>
>>
>>Dim oConnStr As String = "provider=VFPOLEDB.1 ;data source='c:\program files\microsoft visual foxpro 7\samples\data\testdata.dbc';password='';user id=''"
>>
>>' Make connection to VFP database
>>Dim oConn As New OleDbConnection()
>>oConn.ConnectionString = oConnStr
>>oConn.Open()
>>
>>' Create a Command object with select statement
>>Dim strSelect As [String] = "SELECT * FROM ORDITEMS WHERE LINE_NO=?"
>>Dim oSelectCommand As New OleDbCommand(strSelect, oConn)
>>
>>' Create and set value of the parameter
>>oSelectCommand.Parameters.Add("LINE_NO", 1)
>>Dim dr As OleDbDataReader = oSelectCommand.ExecuteReader()
>>dr.Read()
>>MessageBox.Show(dr(0).ToString())
>>
>>
>>>I'm trying to create a simple web form with an OleDbConnection to a Visual FoxPro 7 database (DBC) using the ADO driver for VFP, and an OleDbCommand with an SQL Select query with one parameter. I want to put the results of the query, which should be a few rows from my table, into a DropDownList. The problem is that I always get an error when the OleDbCommand runs ("Object reference to non-object").
>>>
>>>In the VFP table, the parameter field is numeric, N(2) to be precise. Visual Studio .NET creates a parameter collection with one input parameter of type Decimal. I can get this to work fine if the parameter field is character.
>>>
>>>Can somebody please send me an example of working code that executes an OleDbCommand with a parameter against a VFP table, where the parameter field is numeric?
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform