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

ADO Connection Code in C# - Need help Developing

Posted on 2008-10-27
11
893 Views
Last Modified: 2011-10-19
Hi,

I have sample code from a workbook for this ADP API that is written in VB and I need to convert to C# and make it work. I am using VS 2008.

I think this is deprecated code or something because I get errors.

I have also attached what I have so far in a text file.
Sample-VB-Code.pdf
WhatIhaveSoFarInC-.txt
0
Comment
Question by:FindlayIT
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 4

Assisted Solution

by:GO-87
GO-87 earned 100 total points
ID: 22815545


The VB code uses ADO, whereas C# offers you ADO.NET which has many advantages. If you have to use ADO, then it is still available via COM Interop, but I would suggest you look at ADO.NET

Here's a handy tutorial to get you started:

http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx 
 

0
 

Author Comment

by:FindlayIT
ID: 22815612
I have a little experience ADO.Net and I am willing to upgrade this thing to ADO.Net but the data connection is giving me fits. ADP boxes use the Pick operating system and I need help.
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22815994
why you dont download the application data blocks from microsofts website and use that as it will provide you with a already written piece of code
if required you and configure that application block as you need.
hope it helps
ragi
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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 4

Expert Comment

by:GO-87
ID: 22816570
By the way, if you want to save yourself some typing, the VB code in your PDF appears here:
http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=123406
 
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22818909
0
 
LVL 1

Assisted Solution

by:Abh4IT
Abh4IT earned 300 total points
ID: 22819268
You can use either of the following methods

//disconnected
private DataSet CallUsingDataSet()
{

        //method 1 - disconnected dataset

        string connstr=<Connectionstring here>


       string SELECT= "SELECT t1,t2 from TestTable";
       OleDBConnection connection = new Connection(connstr);
       DataAdapter adapter = new OleDBAdapter(SELECT,connection );
         DataSet dataSet=new DataSet();
       adapter.fill(dataSet,"TableName");
         return dataSet;


}
private Datareader CallUsingReader()
{         //method2 connected


       DataReader reader=   new DataReader();
       OleDBConnection connection = new Connection(connstr);
          OleDbCommand command= new OleDbCommand( "SELECT columns FROM tablename", connection)
       connection.Open(); //note the open here
       reader=command.ExecuteReader();
         return reader;
}

Now operator on reader using while(reader.Read()) {reader.GetString()} or on DataSet like
dataSet.Tables["TableName"].Rows (DataRow)

For reference:
http://msdn.microsoft.com/en-us/library/e80y5yhx.aspx

Connectionstrings..
---------------------
http://www.carlprothman.net/Default.aspx?tabid=81

0
 

Author Comment

by:FindlayIT
ID: 22844843
Ok guys I switched to .Net and here is what I have:
 private void button1_Click(object sender, EventArgs e)
        {        

        //method 1 - disconnected dataset
        string constr = "provider=ADPProv.ADPProv.1;host=" + Host.Text;
            constr = constr + ";product=" + Product.Text;
            constr = constr + ";server=" + Server.Text;
            constr = constr + ";password=" + Password.Text;
            constr = constr + ";pooling=TRUE";

           OleDbConnection con = new OleDbConnection(constr);
           
            OleDbCommand command = new OleDbCommand();
            command.CommandType = System.Data.CommandType.TableDirect;
            command.CommandText = "\"Object\"";
            command.Connection = con;
            command.Connection.Open();
                       
            OleDbDataReader reader = command.ExecuteReader();
                                         
            while (reader.Read())
             {
             Output.Items.Add(reader.GetInt32(0));
             }
            reader.Close();
            con.Close();

The only problem is that I am no tfinding the Object because I don't know how to convert this ADO statement to ADO.Net:

It is con.Properties("GROUP") = "ADMIN"

Can anyone tell me how to put this into an OleDBCommand or OleDbConnection object?

Thanks so much. In case you can't tell I am a rank beginner in this ADO stuff

0
 
LVL 1

Expert Comment

by:Abh4IT
ID: 22847450
Hi,

I guess you need to include userid in the connectionstring. Then the database will see if the user is part of which group and handle accordingly.

HTH
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 100 total points
ID: 22847484
if you ignore It is con.Properties("GROUP") = "ADMIN" does your code run and give you the result set?
0
 

Author Comment

by:FindlayIT
ID: 22850771
Yes it runs but it does not give me the "Object" Object metadata but rather a list of objects. So I need to get into the ADMIN group and it should give me what I want.
0
 

Accepted Solution

by:
FindlayIT earned 0 total points
ID: 22853849
I figured it out. See the underlined changes below. I should not have used TableDirect but Text and then any string is cool.

private void button1_Click(object sender, EventArgs e)
{
string constr = "provider=ADPProv.ADPProv.1;host=" + Host.Text;
constr = constr + ";product=" + Product.Text;
constr = constr + ";server=" + Server.Text;
constr = constr + ";password=" + Password.Text;
constr = constr + ";pooling=TRUE";

OleDbConnection con = new OleDbConnection(constr);

OleDbCommand command = new OleDbCommand();
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "group=ADMIN;object=Object";
command.Connection = con;
con.Open();

OleDbDataReader reader = command.ExecuteReader();

int columnCount = reader.FieldCount;
while (reader.Read())
{
for (int i = 0; i < columnCount; i++)
{
Output.Items.Add(reader.GetName(i).ToString()+"= " + reader.GetValue(i).ToString());
}

}

reader.Close();
con.Close();
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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