468,503 Members | 2,039 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,503 developers. It's quick & easy.

Connecting Access DB to VB .net DataGrid

I'm trying to connect a query I made in the Access
database to populate a grid.I'm using the following code
and I get a error:

Specified cast is not valid.

on the first line below. Any Ideas?
Dim DataAdp As OleDbDataAdapter = New OleDbDataAdapter
("GetInvoices", DBvar)
DataAdp.SelectCommand.CommandType =
CommandType.StoredProcedure
If Not IsDBNull(DataAdp) Then

Try
DataAdp.Fill(ds, "Invoices")
Catch ex As Exception
MsgBox(ex.Message,
MsgBoxStyle.Critical, "Error:")
End Try
GrdInvoices.DataSource = dataset.Tables
("Invoices")
End If

ts.MappingName = dataset.Tables
("Invoices").TableName
Nov 20 '05 #1
5 4888
"Sebastian" <Se*******@ilogic.com> schrieb
I'm trying to connect a query I made in the Access
database to populate a grid.I'm using the following code
and I get a error:

Specified cast is not valid.

on the first line below. Any Ideas?
Dim DataAdp As OleDbDataAdapter = New OleDbDataAdapter
("GetInvoices", DBvar)
I've no clue, but.. what is the type of DBVar? It must be a string or an
System.Data.OleDb.OleDbConnection.
DataAdp.SelectCommand.CommandType =
CommandType.StoredProcedure
If Not IsDBNull(DataAdp) Then
Using IsDBNull on a DataAdapter doesn't make sense at all. A DataAdapter is
an object reading and storing records from and into a database.

Try
DataAdp.Fill(ds, "Invoices")
Catch ex As Exception
MsgBox(ex.Message,
MsgBoxStyle.Critical, "Error:")
End Try
GrdInvoices.DataSource = dataset.Tables
("Invoices")
You are reading into "ds", but attaching "dataset"(.tables)?
End If

ts.MappingName = dataset.Tables
("Invoices").TableName

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Actually I'm using ds everywere but I tryed to change it
here to better describe what I was doing (I missed that
last one). However I am useing a variable ds everywhere
which is a type dataset.

DBVar is global connection to the access database.Its used
as follows.
Public DBvar As New ADODB.Connection()
DBvar.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=PalData.mdb")

Is the connection the problem? How do I need to change it
to get it to work with datagrids? Do I need any special
references?

Thanks,
-----Original Message-----
"Sebastian" <Se*******@ilogic.com> schrieb
I'm trying to connect a query I made in the Access
database to populate a grid.I'm using the following code
and I get a error:

Specified cast is not valid.

on the first line below. Any Ideas?
Dim DataAdp As OleDbDataAdapter = New OleDbDataAdapter
("GetInvoices", DBvar)
I've no clue, but.. what is the type of DBVar? It must

be a string or anSystem.Data.OleDb.OleDbConnection.
DataAdp.SelectCommand.CommandType =
CommandType.StoredProcedure
If Not IsDBNull(DataAdp) Then
Using IsDBNull on a DataAdapter doesn't make sense at

all. A DataAdapter isan object reading and storing records from and into a database.
Try
DataAdp.Fill(ds, "Invoices")
Catch ex As Exception
MsgBox(ex.Message,
MsgBoxStyle.Critical, "Error:")
End Try
GrdInvoices.DataSource = dataset.Tables
("Invoices")
You are reading into "ds", but

attaching "dataset"(.tables)?
End If

ts.MappingName = dataset.Tables
("Invoices").TableName

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

.

Nov 20 '05 #3
Hi Sebastian,

The simplest way to test this is first remove that SP.
Test it with a normal SQL txt string, when it than it working it is easy to
change that again for an SP.

The same as Armin wrote do I think that that DBnul dataadapter is the error

What has a DBnull.value to do with a dataadapter?

The commandpart can have no reference, however that is not a DBnull.value
but a Nothing (while the dataadapter is Something).

Cor
Nov 20 '05 #4
"Sebastian" <Se*******@ilogic.com> schrieb
Actually I'm using ds everywere but I tryed to change it
here to better describe what I was doing (I missed that
last one). However I am useing a variable ds everywhere
which is a type dataset.

DBVar is global connection to the access database.Its used
as follows.
Public DBvar As New ADODB.Connection()
DBvar.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=PalData.mdb")

Is the connection the problem? How do I need to change it
to get it to work with datagrids? Do I need any special
references?


You are mixing two (totally) different technologies: ADO and ADO.Net. You
are establishing an ADO connection, but you need an ADO.Net connection
(System.Data.OleDb.OleDbConnection).
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Hi Sebastian,

Armin saw that better than I however to fullfil your question

dim DBVar as new
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=\somepath\mydb.mdb;User Id=admin;Password=;" )

Cor
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by matt.raffel | last post: by
reply views Thread by bill yeager | last post: by
1 post views Thread by bill yeager | last post: by
11 posts views Thread by CM Manager via DotNetMonster.com | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.