Solved

ADODB.Connection.Execute requires arguments

Posted on 2004-04-05
8
2,178 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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