krishanusen
New member
- Joined
- Apr 14, 2021
- Messages
- 4
- Programming Experience
- 1-3
i have getting error following code.
error massage:
database path show in textbox3 & table name show in textbox4.
database records show in datagridview1.
when i select table name from listbox then table name show in textbox4 but database records not showing in datagridview & show error massage.
Dim dbconn As New OleDbConnection
Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbconn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " & TextBox3.Text)
Dim SchemaTable As DataTable
----------------------------------------------------------------------------------------------------------------
database path read from textfile and show in textbox3
Dim FILE_NAME As String = My.Application.Info.DirectoryPath.ToString() & "\INFO.TXT"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)
TextBox3.Text = objReader.ReadToEnd
objReader.Close()
Else
MessageBox.Show("File Does Not Exist")
End If
-------------------------------------------------------------------------------------------------------------------
ListBox1.Items.Clear()
Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source =" & TextBox3.Text)
con.Open()
Dim dt As DataTable = con.GetSchema("TABLES", {Nothing, Nothing, Nothing, "TABLE"})
Dim int As Integer
SchemaTable = con.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, Nothing})
For int = 0 To SchemaTable.Rows.Count - 1
If SchemaTable.Rows(int)!TABLE_TYPE.ToString = "TABLE" Then
'Add items to list box
ListBox1.Items.Add(SchemaTable.Rows(int)!TABLE_NAME.ToString())
End If
Next
End Sub
Private Sub ListBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseClick
TextBox4.Text = ListBox1.Text
Dim query As String = "SELECT * FROM " & TextBox4.Text
' Create a DataAdapter to load the data.
Dim data_adapter As New OleDbDataAdapter(query, dbconn)
' Create a DataTable.
Dim data_table As New DataTable()
Try
data_adapter.Fill(data_table)
Catch ex As Exception
MessageBox.Show("Error executing query " & query & vbCrLf & ex.Message)
End Try
' Bind the DataGridView to the DataTable.
DataGridView1.DataSource = data_table
DataGridView1.ReadOnly = True
error massage:
database path show in textbox3 & table name show in textbox4.
database records show in datagridview1.
when i select table name from listbox then table name show in textbox4 but database records not showing in datagridview & show error massage.
Dim dbconn As New OleDbConnection
Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbconn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " & TextBox3.Text)
Dim SchemaTable As DataTable
----------------------------------------------------------------------------------------------------------------
database path read from textfile and show in textbox3
Dim FILE_NAME As String = My.Application.Info.DirectoryPath.ToString() & "\INFO.TXT"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)
TextBox3.Text = objReader.ReadToEnd
objReader.Close()
Else
MessageBox.Show("File Does Not Exist")
End If
-------------------------------------------------------------------------------------------------------------------
ListBox1.Items.Clear()
Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source =" & TextBox3.Text)
con.Open()
Dim dt As DataTable = con.GetSchema("TABLES", {Nothing, Nothing, Nothing, "TABLE"})
Dim int As Integer
SchemaTable = con.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, Nothing})
For int = 0 To SchemaTable.Rows.Count - 1
If SchemaTable.Rows(int)!TABLE_TYPE.ToString = "TABLE" Then
'Add items to list box
ListBox1.Items.Add(SchemaTable.Rows(int)!TABLE_NAME.ToString())
End If
Next
End Sub
Private Sub ListBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseClick
TextBox4.Text = ListBox1.Text
Dim query As String = "SELECT * FROM " & TextBox4.Text
' Create a DataAdapter to load the data.
Dim data_adapter As New OleDbDataAdapter(query, dbconn)
' Create a DataTable.
Dim data_table As New DataTable()
Try
data_adapter.Fill(data_table)
Catch ex As Exception
MessageBox.Show("Error executing query " & query & vbCrLf & ex.Message)
End Try
' Bind the DataGridView to the DataTable.
DataGridView1.DataSource = data_table
DataGridView1.ReadOnly = True