qiera 0 Newbie Poster

i am new with vb and this is my code that i work with..
there are errors in my code to view data from ms access into data grid..
can anyone help me to solve this problem?
thanks...

Imports System.Data.OleDb

Public Class frmView

Inherits System.Windows.Forms.Form

Dim DB As OleDb.OleDbConnection
Dim Dc As New OleDb.OleDbCommand
Dim Da As New OleDb.OleDbDataAdapter
Dim Ds As New DataSet
Dim Nextb As Long
Dim PrevB As Long
Dim TotalC As Long

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
DB.Open()
Da = New OleDb.OleDbDataAdapter("Select * from emailcontact where Name = like '%''" & txtName.Text & "' ", DB)
Ds = New DataSet("MS")
Da.Fill(Ds, "MS")
DataGrid1.DataSource = Ds
DataGrid1.DataMember = "MS"
DB.Close()

End Sub

Private Sub frmView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
COnnect()

End Sub

Private Sub COnnect()
Nextb = 0
PrevB = 0
Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\newcontact2010.mdb"


Try
DB = New OleDbConnection("provider= Microsoft.Jet.OLEDB.4.0; Data Source ='" & STrPath & "'")
Dc = New OleDbCommand("Select * from emailcontact")

DB.Open()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "")
End
End Try
Dc.Connection = DB
Da = New OleDb.OleDbDataAdapter("Select * from emailcontact ", DB)
Ds = New DataSet("MS")
Da.Fill(Ds, "MS")
DataGrid1.DataSource = Ds.Tables(0).DefaultView
Dim dTable As DataTable
For Each dTable In Ds.Tables

Dim dgStyle As DataGridTableStyle = New DataGridTableStyle
dgStyle.MappingName = dTable.TableName

Next

DataGrid1.CaptionText = "Name"

Dim x = Ds.Tables("ms").Rows.Count()
TotalC = x - 1

Dim Dr As OleDb.OleDbDataReader = Dc.ExecuteReader
txtName.Text = ""
While Dr.Read
txtName.Text.Add(Dr("Name"))
End While
DB.Close()

End Sub

End Class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.