I am testing a simple query to get data from an AS400 database. I am not sure if the way I am using the SQL query is correct.
I get an error: \"The
If you're going to connect to the AS400 using .NET, first of all you should use the IBM.Data.DB2.iSeries .NET provider from IBM. According IBM's documentation, this is the preferred method for calling sql:
iDB2Connection conn = new IDB2Connnection(connectionstring);
iDB2Command cmd = null;
try
{
conn.Open();
string sql = "select * from somelibrary.sometable where a = @A and b = @B";
cmd = conn.CreateCommand();
cmd.CommandText = sql;
cmd.DeriveParameters(); //this will talk to the AS400 to determine the param types
cmd.Parameters["@A"].Value = Avalue;
cmd.Parameters["@B"].Value = Bvalue;
//execute the query
cmd.ExecuteScalar(); //doesn't have to be Scalar but you get the idea
}
catch (Exception ex)
{
//handle your exceptions
}
finally
{
cmd.Dispose();
conn.Close();
}