2011年11月30日 星期三

{C#-SQL資料庫}OleDb connection寫法

OleDbConnection conn = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();

conn.ConnectionString = @"Provider=MSDAORA;Data Source=xxxx;User Id=xxxxx;Password=xxxxxx;";
 //conn.ConnectionString = ConfigurationManager.ConnectionStrings["cimdb-ConfigLab"].ConnectionString;
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"select * From abc where aufnr ='xx' ";
 conn.Open();
//取得第一筆第一欄資料
object s = cmd.ExecuteScalar();
conn.Close();
this.textBox1.Text = s.ToString();