Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't insert into VFP table
Message
From
30/12/2006 15:43:02
 
 
To
30/12/2006 13:43:28
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01181015
Message ID:
01181085
Views:
8
>Oh yeah. I forgot. C# is one of those pesky strong type language. :)
>
>Thank you Bonnie.


You're welcome, Sam. Just keep in mind to take advantage of Intellisense. It would have shown you the signature of the method, including the description of what is returned.

~~Bonnie




>
>
>>Sam,
>>
>>Your problem is that the ExecuteNonQuery() doesn't return a DataReader. It returns an int indicating how many rows were processed.
>>
>>
>>        int NumRows = cCmd.ExecuteNonQuery();
>>
>>
>>or if you don't care about how many rows were processed, you can simply leave it out:
>>
>>
>>        cCmd.ExecuteNonQuery();
>>
>>
>>~~Bonnie
>>
>>
>>
>>>Sorry here it is.
>>>
>>>
>>>// Add these to top
>>>using System;
>>>using System.Data;
>>>using System.Data.OleDb;
>>>
>>>public class customertbl
>>>{
>>>    static void Main()
>>>    {
>>>        string strConn = @"Provider=VFPOLEDB;Data source=C:\Program Files\Microsoft Visual FoxPro 9\Samples\Data\testdata.dbc;";
>>>
>>>        string strQuery = "INSERT INTO customer (cust_id, company, contact) VALUES ('SAMAHN', 'SKAHN REST', 'Sam Ahn')";
>>>
>>>        OleDbConnection cConnect = new OleDbConnection(strConn);
>>>        cConnect.Open();
>>>
>>>        OleDbCommand cCmd = new OleDbCommand(strQuery, cConnect);
>>>        OleDbDataReader cRdr = cCmd.ExecuteNonQuery();
>>>
>>>        cRdr.Close();
>>>        cConnect.Close();
>>>    }
>>>
>>>}
>>>
>>>
>>>
>>>
>>>>>I'm trying to insert a record into customer table (foxpro).
>>>>>
>>>>>I'm using ...ExecuteNonQuery();
>>>>>
>>>>>My insert statment looks like this:
>>>>>sqlCom = "INSERT INTO customer (cust_id, company, contact) VALUES ('SAMAHN', 'SKAHN REST', 'Sam Ahn')"
>>>>>
>>>>>
>>>>>The error I keep getting is:
>>>>>"Cannot implicitly convert type 'int' to 'System.Data.OleDb.OleDbDataReader'
>>>>>
>>>>>What does it not like?
>>>>>
>>>>>TIA.
>>>>
>>>>Sam,
>>>>You have to post more of the code, like where you create the connection to the database/table.
>>>>
>>>>Einar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform