Solved

ADODB.Connection.Execute requires arguments

Posted on 2004-04-05
8
2,143 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now