. NET connect to SQL SERVER via ODBC

Source: Internet
Author: User
Tags dsn sql server driver

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.