標籤:
using System.Data.Odbc;//in order to use databaseprivate void button_login_Click(object sender, EventArgs e) { string strSqlQuery = string.Format("select * from USER where username=‘{0}‘;",textBox_username.Text); string connStr = ""; connStr += "Dsn=SQLite3 Datasource;database=D:\\database\\jiche.db;StepAPI=0;SyncPragma=;NoTXN=0;Timeout=;ShortNames=0;LongNames=0;NoCreat=0;NoWCHAR=0;FKSupport=0;JournalMode=;OEMCP=0;LoadExt=;BigInt=0;JDConv=0;"; //cnStr += "Driver={SQLite3 ODBC Driver};database=D:\\database\\jiche.db;StepAPI=0;SyncPragma=;NoTXN=0;Timeout=;ShortNames=0;LongNames=0;NoCreat=0;NoWCHAR=0;FKSupport=0;JournalMode=;OEMCP=0;LoadExt=;BigInt=0;JDConv=0;"; OdbcConnection conn = new OdbcConnection(connStr); OdbcDataAdapter da = new OdbcDataAdapter(strSqlQuery, conn); //引用資料庫連接dbconn並依據SQL語句"select * from kaizhi"建立OleDbDataAdapter對象da DataSet ds = new DataSet(); //建立DataSet對象 da.Fill(ds); if(ds.Tables[0].Rows.Count>=1) { if (ds.Tables[0].Rows[0]["password"].ToString() == textBox_password.Text) { //MessageBox.Show("登陸成功"); FormMain form_main = new FormMain(this); form_main.Show(); this.Hide(); } } }
今天早晨試了一下,用oledb連不上,換成odbc就好了。
C# 串連SQLite ODBC driver