Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ADODB.Connection.Execute requires arguments

Posted on 2004-04-05
8
Medium Priority
?
2,199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 12

Accepted Solution

by:
dfiala13 earned 2000 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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