关于C#.net Windows Forms应用程序中与MS Access 2007数据库通信的错误 [英] Regarding error in c#.net windows forms application to communicate with ms access 2007 database

查看:87
本文介绍了关于C#.net Windows Forms应用程序中与MS Access 2007数据库通信的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ms.net4.0,windows7,ms access2007数据库.
我在ms Access中创建的数据库名称为"mydata",表名称为"information".
我正在创建带有图表控件的Windows窗体应用程序,以图形方式表示信息"表数据.但是出现以下异常:
***"Micro Soft.jet.oledb 4.0"提供程序未在本地计算机上注册.**
我已经设置了目标CPU--AnyCPU,x86,并且安装了"Access DataBase Engine.exe文件".
但是我仍然遇到相同的错误,请发送更多信息来解决它.

使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
使用System.Data.OleDb;
使用System.Windows.Forms.DataVisualization.Charting;

命名空间chartform
{
公共局部类Form1:Form
{
OleDbConnection con =新的OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0:Data Source = C:\\ Users \\ baswaraj \\ Documents \\ mydata.accdb; Persist Security Info = False;");
公共Form1()
{
InitializeComponent();
}

private void button1_Click(对象发送者,EventArgs e)
{
if(textBox1.Text ==")
{
MessageBox.Show(输入日期和时间");
textBox1.Focus();
返回;
}
tabControl1.SelectedIndex = tabControl1.SelectedIndex +1;
字符串查询=插入信息值(""+ textBox1.Text +"," + textBox2.Text +," + textBox3 +)";
OleDbCommand cmd =新的OleDbCommand(query,con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

private void chart1_Click(对象发送者,EventArgs e)
{
字符串查询1 =通过convert(char(8),dateandtime,10)从工作表组中选择convert(char(8),dateandtime,10)作为dateinfo,sum(nofcigarette)作为ciginfo,";
OleDbDataAdapter da =新的OleDbDataAdapter(query1,con);
DataSet ds = new DataSet();
da.Fill(ds);
chart1.DataSource = ds;
chart1.DataBind();
chart1.Series ["Series1"].ChartType = SeriesChartType.Column;
chart1.Series ["Series1"].XValueMember =日期信息";
chart1.Series ["Series1"].YValueMembers ="nofc信息";
chart1.ChartAreas ["ChartArea1"].AxisX.Title =日期";
chart1.ChartAreas ["ChartArea1"].AxisY.Title =无计数";
}
}
}

Hi i am using ms.net4.0, windows7, ms access2007 database.
I was created database name as "mydata" and table name as "information" in ms access
I was creating windows forms application with chart control to represent "information" table data as graphical manner. But get following exception:
***"The Micro Soft.jet.oledb 4.0" provider is not registered on the local machine.**
I had already set Target CPU--AnyCPU, x86 and i was installed "Access DataBase Engine.exe file".
But i still get the same error please send more information to resolve it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Windows.Forms.DataVisualization.Charting;

namespace chartform
{
public partial class Form1 : Form
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0:Data Source=C:\\Users\\baswaraj\\Documents\\mydata.accdb; Persist Security Info=False;");
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text=="")
{
MessageBox.Show("enter date and time");
textBox1.Focus();
return;
}
tabControl1.SelectedIndex = tabControl1.SelectedIndex + 1;
string query = "insert into information values(''" + textBox1.Text + "''," + textBox2.Text + "," + textBox3 + ")";
OleDbCommand cmd = new OleDbCommand(query, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

private void chart1_Click(object sender, EventArgs e)
{
string query1 = "select convert(char(8), dateandtime, 10) as dateinfo, sum(nofcigarette) as ciginfo from sheet group by convert(char(8), dateandtime, 10)";
OleDbDataAdapter da = new OleDbDataAdapter(query1, con);
DataSet ds = new DataSet();
da.Fill(ds);
chart1.DataSource = ds;
chart1.DataBind();
chart1.Series["Series1"].ChartType = SeriesChartType.Column;
chart1.Series["Series1"].XValueMember = "date info";
chart1.Series["Series1"].YValueMembers = "nofc info";
chart1.ChartAreas["ChartArea1"].AxisX.Title = "Date";
chart1.ChartAreas["ChartArea1"].AxisY.Title = "No-of-Counts";
}
}
}

推荐答案

查看以下内容: http://forums .asp.net/t/1008321.aspx [ ^ ]
Look at the following: http://forums.asp.net/t/1008321.aspx[^]


这篇关于关于C#.net Windows Forms应用程序中与MS Access 2007数据库通信的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆