1

I would think this would be a fairly common thing, and easy to find in google, but so far I haven't had much luck. I would like my application to connect to the i-series AS400 system using some method, run an SQL statement over an AS400 physical file, return a result set, and then have my visual c# program process the result set. I've heard of ADODB, ODBC, DB2, and OLEDB. Can someone show me an example of the syntax for getting one of these methods to work? I'd prefer to use a method that isn't dependent on having certain software such as client access, and am trying to avoid using something like ODBC due to the fact you have to configure the DSN. I've searched and searched, but the most code I can find is what the connection string should look like. Any help is appreciated!

Thanks!

1
  • I finally got one working using ADODB. Thanks anyway! Commented Jun 10, 2012 at 13:18

1 Answer 1

2

I've found this question during my search.

You can connect to the IBM iSeries using OLEDB connection and run SQL queries then retrieve the results but you need some steps first.

  1. You need the AS400 .Net data provider. - http://www-03.ibm.com/systems/power/software/i/access/windows/dotnet.html

  2. You need to write your connection string. - http://www.connectionstrings.com/as-400

  3. Some Code, then

    string ConnectionString = AS400ConnectionString;
    OleDbConnection _Connection = new OleDbConnection(ConnectionString);
    OleDbCommand _Command = _Connection.CreateCommand();
    
                string strQuery = string.Empty;
                strQuery += @"SELECT * FROM Contacts";
    
                if (string.IsNullOrEmpty(strQuery))
                {
                    throw (new Exception("No Library Setup"));
                }
    
                _Command.CommandText = strQuery;
                if (_Connection.State != ConnectionState.Open)
                    _Connection.Open();
    
                OleDbDataReader reader = _Command.ExecuteReader();
    
                while (reader.Read())
                {
                    //Your Logic
                }
    
                reader.Close();
                if (_Connection.State != ConnectionState.Closed)
                    _Connection.Close();
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.