Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to display the DataBase Data in VB Form in Grid view ..... I know how to Display Data via DataGrid View from datasources.But i need to display data from code.My Code for Connecting Database is
VB
Dim cnnOLEDB As New OleDbConnection
    Dim cmdOLEDB As New OleDbCommand
    Dim cmdInsert As New OleDbCommand
    Dim cmdUpdate As New OleDbCommand
    Dim cmdDelete As New OleDbCommand
    Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\SMSToolDB.mdb"
cnnOLEDB.ConnectionString = strConnectionString
        cnnOLEDB.Open()



Any One please Help me.......
Posted
Updated 8-Aug-17 23:53pm
v2
Comments
uspatel 29-Nov-11 0:22am    
did You make any efforts to bind data with gridview?

Try this one :

VB
Dim objda As OleDbDataAdapter= New OleDbDataAdapter
        Public con As New OleDb.OleDbConnection             'Creating Connection object       
        Dim objdataset As DataSet = New DataSet
        Dim dv As DataView
        objda.SelectCommand = New OleDbCommand
        OpenConnection()                                    'Open your DataBase Connection First
        objda.SelectCommand.CommandText = "Select * FROM TableName"
        objda.Fill(objdataset, "TableName")
        dv = New DataView(objdataset.Tables("TableName"))
        DataGridView1.DataSource = dv

Public Sub OpenConnection()
        If con.State = ConnectionState.Open Then            'Checking Connection State
            con.Close()                                     'Closing Connection
        End If
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\DataBaseName.mdb;Persist Security Info=True;"
        Try
            con.Open()                                      'Opening Connection
        Catch ex As Exception                               'Providing Error Message
            MessageBox.Show("Uable to Connect", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End                                             'Closing Application
        End Try
 
Share this answer
 
v3
Comments
Himachandra 29-Nov-11 0:33am    
Error: objda is not declared
Himachandra 29-Nov-11 0:33am    
How to declare objda......
Himachandra 29-Nov-11 0:37am    
OpenConnection() is not declare error has been occured?
Manoj K Bhoir 29-Nov-11 8:10am    
Check Updated dolution!
Chhavi Verma 4-Feb-13 0:01am    
problem: I want to display data from access database in vb.net web application gridview.m sending my code..


Dim connectionstring As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\user\Documents\rcsd.accdb; Persist Security Info =False;"
Dim sql As String = ("select class1,sec1,fname1 from table1 where class1='" + dpclass1.Text + "' and sec1='" + dpsec1.Text + "'")
Dim conn As New OleDbConnection(connectionstring)
Dim dataadapter As New OleDbDataAdapter(sql, conn)
Dim ds As New DataSet()

conn.Open()
dataadapter.Fill(ds, "table1")
conn.Close()
GridView1.DataSource = ds
GridView1.DataMember = "table1"
GridView1.DataBind()



//its not showing the result in gridview,even not the gridvew.. please help
This will helps
GridView.DataBind Method
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900