Solved

ADO Connection Code in C# - Need help Developing

Posted on 2008-10-27
11
895 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 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
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 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

Industry Leaders: 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!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

763 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