using System.Data.Odbc;//in order to use database private 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就好了。
时间: 2024-11-10 08:16:13