Private Sub OpenFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileToolStripMenuItem.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "mdb files (*.mdb)|*.mdb|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
myConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & openFileDialog1.FileName
Dim cmd As New OleDb.OleDbCommand("SELECT Image001 FROM [DDCOS] WHERE RecNum = @RecNum", con)
con.ConnectionString = myConString
Dim path As New IO.DirectoryInfo(openFileDialog1.FileName)
Dim childLen As Integer = path.Name.Length
Dim parentLen As Integer = path.Parent.Name.Length
Dim path2 As String = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.Length - (childLen + parentLen + 1)) & "Images"
con.Open()
datagridshow()
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
End Sub
Private Sub CARD_DECK_ENTRY_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = myConString
con.Open()
datagridshow()
End Sub
Private Sub datagridshow()
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
Dim ODDA As New OleDbDataAdapter
da = New OleDbDataAdapter("Select * from Data001", con)
da.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
con.Close()
End Sub
上面的代码是我浏览mdb的代码,并在datagrid上输入它的值。我正打算在左侧显示字段名称,在右侧显示它的值。该怎么办?
答案 0 :(得分:0)
根据我的问题,
datatable
。column
中添加所需数量datatable
的名称。row
添加到datatable
。row
column
填充datatable
OleDb
中填充的数据的新Query
。bind
这个新datatable
到datagridview
为datasource
。这可能会对你有帮助。