当前位置:Gxlcms > 数据库问题 > C# ACCESS数据库链接

C# ACCESS数据库链接

时间:2021-07-01 10:21:17 帮助过:2人阅读

 private void button1_Click(object sender, EventArgs e)
        {          

string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"E:\map\SansMachine.mdb";

            OleDbConnection objConnection = new OleDbConnection(strConnection);  //建立连接  
            objConnection.Open();  //打开连接
            OleDbCommand sqlcmd = new OleDbCommand(@"select * from ParamFactValue where TestNo=10", objConnection);  //sql语句  
            OleDbDataReader reader = sqlcmd.ExecuteReader();              //执行查询 
      
            while (reader.Read())
            { //这个read调用很重要!不写的话运行时将提示找不到数据  
                //age = (int)reader.getstring(0);   //取得字段的值  

                textBox1.Text = reader["Name"].ToString();
                textBox2.Text = reader["TheValue"].ToString();

                
            }

            objConnection.Close();
            reader.Close();

C# ACCESS数据库链接

标签:

人气教程排行