码迷,mamicode.com
首页 > 数据库 > 详细

C# ACCESS数据库链接

时间:2016-05-27 16:23:22      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:

 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数据库链接

标签:

原文地址:http://www.cnblogs.com/rosesmall/p/5534843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!