ADO Connection Code in C# - Need help Developing

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
FindlayITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GO-87Commented:


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
FindlayITAuthor Commented:
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
Anurag ThakurTechnical ManagerCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

GO-87Commented:
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
Anurag ThakurTechnical ManagerCommented:
0
Abh4ITCommented:
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
FindlayITAuthor Commented:
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
Abh4ITCommented:
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
Anurag ThakurTechnical ManagerCommented:
if you ignore It is con.Properties("GROUP") = "ADMIN" does your code run and give you the result set?
0
FindlayITAuthor Commented:
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
FindlayITAuthor Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.