Solved

ADO Connection Code in C# - Need help Developing

Posted on 2008-10-27
11
884 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now