选择.Mdb数据库文件使用Oledb打开I Vb2010,用于图表。 [英] Selecting .Mdb Database File To Open I Vb2010 With Oledb, For Chart.
问题描述
您好。我试图创建一个程序(vb2010),可以连接到选定的.mdb数据库,并根据其中的数据绘制图表。我们的想法是能够选择打开哪个文件,并根据其中的数据绘制图表。目前我能够将数据库的路径保存为字符串,但是我在保存数据库内容时遇到问题(不知道是否必须)并将其链接到图表数据源。我已经按照一些教程,但他们似乎没有回答我的问题。我没有MS Access,所以我不能将骷髅(或任何它们被称为)拖放到我的代码中。
可以任意1个PLZ帮助吗?
这是我的数据库:
这是我到目前为止的代码
Hi. Im trying to make a program (vb2010) that can connect to a selected .mdb database and draw a chart based on the data in it. The idea is to be able to selct which file to open, and draw a chart based on what data is in it. Currently i am able to save the path to the db as a string, but i have problems saving the content of the db (don't know if i have to) and link it to the charts datasource. I've followed some tutorials but they dont seem to answe my question. I do not have MS Access ,so i cant drag and drop skeletons (or whatever they are called) into my code.
Can any1 plz help?
this is my database:
This is my code so far
Imports System.Data.OleDb
Public Class Form1
Dim connString As String
Dim dbConn As OleDbConnection
Dim dbComm As OleDbCommand
Dim dbDataSet As DataSet
Dim dbDataAdapter As OleDbDataAdapter
Dim dbDataReader As OleDbDataReader
Dim tab1 As DataTable
Dim Item(2) As String
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
openFD.InitialDirectory = "C:\"
openFD.Title = "Open a .mdb database"
openFD.Filter = ".mdb |*.mdb"
openFD.ShowDialog()
connString = openFD.FileName
TextBox1.Text = connString
''''''''''''
Dim Table_ As String = "Table1"
Dim query As String = "SELECT * FROM " & Table_
Dim MDBConnString_ As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=connString;"
dbConn = New OleDbConnection(MDBConnString_)
dbConn.Open()
dbComm = New OleDbCommand(query, dbConn)
dbDataAdapter = New OleDbDataAdapter(dbComm)
dbDataAdapter.Fill(dbDataSet, Table_)
dbConn.Close()
tab1 = dbDataSet.Tables(Table_)
Dim row As DataRow
For Each row In tab1.Rows
Item(0) = row(0)
Item(1) = row(1)
Dim NextListItem As New ListViewItem(Item)
Next
End Sub
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub openFD_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles openFD.FileOk
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Chart1.DataSource = tab1
End Sub
End Class
推荐答案
问题是我不知道如何存储数据/或绘制它在图表中。我还需要能够缩放并对数据进行一些数学运算(在某些间隔上的平均值),但这是我将要看到的东西。
我不确定我需要数据适配器,但我对此有点新鲜。此外,我需要访问的表是众多(在数据库中)之一,我不知道如何达到特定的一个。现在,我需要知道的是两件事。
1
如何在我的计算机上设置alink到任何.mdb文件,使用oledb。
2
如何在图表中显示.mdb文件中的数据。
the problem is i don't know how to store the data/or draw it in the chart. I also need to be able to zoom and do some mathematical operations on the data (mean value on certain intervals), but that is something i will look at down the road.
I'm not sure i need the dataadapter, but I'm a bit new to this. Also, the table i need acces to is one of many (in the db), And I'm not sure how to reach that specific one. For now, what i need to know is 2 things.
1
How to set up alink to any .mdb file on my computer, using oledb.
2
How to display the data in the .mdb file in a chart.
>
这篇关于选择.Mdb数据库文件使用Oledb打开I Vb2010,用于图表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!