Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ADO Connection Code in C# - Need help Developing

Posted on 2008-10-27
11
Medium Priority
?
904 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
[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
  • 3
  • 2
  • +1
11 Comments
 
LVL 4

Assisted Solution

by:GO-87
GO-87 earned 400 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
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 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 1200 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 400 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

715 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