標籤:style blog color io os ar sp div on
通過ODBC串連到SQL SERVER的兩種方法:
一、通過載入SQL SERVER驅動方式;
二、通過配置DSN名稱;
string constr = "driver={sql server};database=" + databaseNAME+ ";server=" + 伺服器位址 + ";"//SQL SERVER驅動 constr += "UID=invuser;PWD=1;"OdbcCommand cmd_s = new OdbcCommand(sSQL, conn_odbc); OdbcDataReader reader_s = cmd_s.ExecuteReader();//執行查詢 int iCZ = 0; while (reader_s.Read()) { JLBH_OUT.Add(data.iJLBH); iCZ=1; } reader_s.Close();sSQL = " insert into dbo(操作員名稱,匯出日期) values ";string stmp = "(";stmp += "‘" + sDJRMC + "‘,getdate()";stmp += ")";sSQL += stmp;OdbcCommand cmd_in = new OdbcCommand(sSQL, conn_odbc);int iInsert = cmd_in.ExecuteNonQuery(); //執行插入conn_odbc.Close();
OdbcConnection cn; OdbcCommand cmd; string MyString; MyString="Select * from dbo"; cn= new OdbcConnection("dsn=myDSN;UID=invuser;PWD=1;");//通過DSN cmd=new OdbcCommand(MyString,cn); cn.Open(); MessageBox.Show("Connected"); cn.Close();
.NET通過ODBC 串連 SQL SERVER