There are two ways to connect to SQL Server via ODBC:
One, by loading the SQL Server drive mode;
Second, by configuring the DSN name;
stringConstr ="driver={sql Server};d atabase="+ databasename+"; server="+ Server address +";the//sql Server driver Constr+="Uid=invuser; pwd=1;"OdbcCommand cmd_s=NewOdbcCommand (sSQL, CONN_ODBC); OdbcDataReader reader_s= Cmd_s.executereader ();//Execute Query intICZ =0; while(Reader_s.read ()) {jlbh_out. ADD (DATA.IJLBH); ICZ=1; } reader_s.close (); sSQL="INSERT INTO dbo (operator name, export date) values";stringSTMP ="("; Stmp+="'"+ SDJRMC +"', GETDATE ()"; Stmp+=")"; sSQL+=Stmp;odbccommand cmd_in=NewOdbcCommand (sSQL, CONN_ODBC);intIinsert = cmd_in. ExecuteNonQuery ();//Perform an InsertConn_odbc. Close ();
odbcconnection cn; OdbcCommand cmd; string MyString; MyString = select * FROM dbo " ; CN = new OdbcConnection ( " DSN=MYDSN; Uid=invuser; pwd=1; " ); //through DSN cmd =new OdbcCommand (MYSTRING,CN); cn. Open (); MessageBox.Show ( connected Span style= "color: #800000;" > " ); cn. Close ();
. NET connect to SQL SERVER via ODBC