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
Solved

ADODB.Connection.Execute requires arguments

Posted on 2004-04-05
8
2,156 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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