2011年12月1日 星期四

{C#-IBM_DB2}DB2連結

using IBM.Data.DB2;
using IBM.Data.DB2Types;

DB2Connection conn = new DB2Connection();
DB2Command cmd = new DB2Command();

conn.ConnectionString = ConfigurationManager.ConnectionStrings["ABC"].ConnectionString;
cmd.Connection = conn;cmd.CommandType = CommandType.Text;
DB2DataAdapter da = new DB2DataAdapter(cmd);
DataSet ds = new DataSet();

cmd.Parameters.Clear();
cmd.Parameters.Add("@MO", DB2Type.VarChar, 16).Value = mo;
cmd.CommandText = @"SELECT *
                                FROM abc
                                WHERE aufnr=LPAD(@MO,12,'0')";
ds = null;
ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
return ds;