PC Review


Reply
Thread Tools Rate Thread

Connecting Access DB to VB .net DataGrid

 
 
Sebastian
Guest
Posts: n/a
 
      13th May 2004
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
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      13th May 2004
"Sebastian" <(E-Mail Removed)> 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

 
Reply With Quote
 
Sebastian
Guest
Posts: n/a
 
      13th May 2004
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" <(E-Mail Removed)> 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
>
>.
>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th May 2004
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


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      13th May 2004
"Sebastian" <(E-Mail Removed)> 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

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th May 2004
Hi Sebastian,

Armin saw that better than I however to fullfil your question

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

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting a textfile to a datagrid motimh@hotmail.com Microsoft VB .NET 9 28th Jan 2005 06:05 PM
Att: Cor Ligthert - re: Connecting a textfile to a datagrid moti Microsoft VB .NET 1 27th Jan 2005 08:26 AM
Connecting to an Access DB =?Utf-8?B?Ym1lcnNlcmVhdUB6ZWxsZS5jb20=?= Microsoft Frontpage 3 28th Oct 2004 07:41 PM
Connecting to access Justin Busch Microsoft VB .NET 2 1st Oct 2004 04:09 PM
connecting to access db Kavvy Microsoft C# .NET 1 4th Aug 2004 01:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:09 PM.