Solved

ADODB.Connection.Execute requires arguments

Posted on 2004-04-05
8
2,160 Views
Last Modified: 2011-10-03
Hi all,
I have been trying to use ADO in C#, which I am familar with in VB6.

When I try and use the Execute method of the Connection (Connection.Execute) it requires parameters.  (string commandtext, out RecordsAffected, int Options).

I am trying to use:
ADODB.Connection mcnn;  //This is setup and connected in another function - just here to show declare
ADODB.Recordset rs;
rs = mcnn.Execute(sSQL);

The other parameters used to be optional but when I try and compile it says "No Overload method for method "Execute" takes 1 arguments"

At first I thought I was using ADO.Net, so I unferenced ADODB and selected ADO 2.6 from the COM tab of the references, but it still happens.  There is probably some simple answer for what I am doing wrong here but I can't find it.
0
Comment
Question by:TimW1
  • 4
  • 4
8 Comments
 
LVL 12

Accepted Solution

by:
dfiala13 earned 500 total points
ID: 10762768
The recordset no longer exists in ADO.NET.  You have DataReaders (forward-only recordsets if you will) and DataTables (scrollable recordsets).

Here's an overview of ADO.NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconoverviewofadonet.asp

Here's one way to get data from a SQLServer database using ADO.NET. This fills a DataTable...

SqlConnection  conn = new SqlConnection("yourconnectionstring");
conn.Open();
SqlCommand cmd = new SqlCommand(sSQL, conn);
SqlDataAdpater da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

You can also use a reader to read the records....

SqlConnection  conn = new SqlConnection("yourconnectionstring");
conn.Open();
SqlCommand cmd = new SqlCommand(sSQL, conn);
SqlDataReader sdr = cmd.ExecuteReader();
object[] objValArray = null;
while(sdr.Read())
{
   sdr.GetValues(objValArray);

}

These are just come basic examples.  You can also use StoredProcs. Check out the link for a fuller look at all the tools available.  Let me know if you have any questions.
0
 
LVL 3

Author Comment

by:TimW1
ID: 10763113
Ok, thanks.  I will try that code out.  However, can you tell me why I can't use recordsets when I'm not using ADO.Net?  I referenced COM->Active Data Objects 2.6 Library.  Shouldn't I be able to use the previous versions of ADO through interop?

0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10763129
You COULD use the old versions of ADO, but why-o-why would you do that? If you are doing everything else in .NET why add in an extra layer (InterOp) to talk to COM to use an older technology?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:TimW1
ID: 10763210
I agree, and I will use the new version but I still need to know why it wouldn't work even when I referenced the older com dll.
Any ideas?
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10763238
Well, the last 2 arguments for conn.Execute are optional in ADO 2.6,

However, it could be that the InterOp wrapper doesn't know how to handle optional parms and requires you to include them.  Try passing nulls for the last 2 arguments and see if that works.
0
 
LVL 3

Author Comment

by:TimW1
ID: 10770904
That sounds possible.  Ok thanks.

Tim
0
 
LVL 3

Author Comment

by:TimW1
ID: 10771137
Can you please tell me what reference you add to use SqlCommand, SqlConnection etc.

Thanks
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10771522
System.Data.SqlClient
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question