Connecting Tech Pros Worldwide Forums | Help | Site Map

VB.NET: display data on datagrid gives error

Newbie
 
Join Date: Oct 2005
Posts: 1
#1: Oct 16 '05
i'm very new to SQL Server and VB.Net 2003

i'm trying to display data on a DataGrid and it's keeps given me an error

this is the code i'm using and i hope someone can help


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
UpdateDataGrid("SELECT * FROM Main")
End Sub


Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
UpdateDataGrid("SELECT * FROM Main")
End Sub


Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
dgDisplay.Dispose()
UpdateDataGrid("SELECT * FROM Main")
End Sub


Sub UpdateDataGrid(ByVal sqlStr As String)
Dim dt As New DataTable
Dim connStr As String = "provider=microsoft.jet.oledb.4.0;" & "data source = PriManagement.mdb"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
[COLOR=DarkRed]dataAdapter.Fill(dt)[/COLOR] this is where i get my error :confused:
dataAdapter.Dispose()
dgDisplay.DataSource = dt
End Sub
Attached Images
File Type: jpg Untitled-1.jpg (38.2 KB, 112 views)

nateraaaa's Avatar
Expert
 
Join Date: May 2007
Location: Illinois
Posts: 663
#2: Dec 4 '08

re: VB.NET: display data on datagrid gives error


Try the following code found on MSDN

Expand|Select|Wrap|Line Numbers
  1. [Visual Basic] 
  2. Public Function SelectOleDbSrvRows(dataSet As DataSet, connection As String, query As String) As DataSet
  3.     Dim conn As New OleDbConnection(connection)
  4.     Dim adapter As New OleDbDataAdapter()
  5.     adapter.SelectCommand = new OleDbCommand(query, conn)
  6.     adapter.Fill(dataset)
  7.     Return dataset
  8. End Function
  9.  
Reply