473,378 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 4991
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Morgan | last post by:
I have Enterprise Manager on my local machine. For the last twelve months it has been connecting without problem to my online SQL Server database provided by my ISP. Three weeks ago the ISP...
2
by: matt.raffel | last post by:
Im running XP Pro with SQL Server 2000 SP3 installed on my local machine. I've created a webpage that has a sqlConnection, sqlDataApdapter, a dataset, and a datagrid. I've gone though all the...
0
by: bill yeager | last post by:
I have a datalist displaying parent information and a datagrid presenting child information. The data is being rendered just fine. The datagrid has template columns on it that I cannot gain access...
1
by: bill yeager | last post by:
I did some more debugging and found the following: 1) I placed the following code in the button event just to see if I could cycle thru the datagrid control collection: <code> Dim strhello As...
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
7
by: Alex | last post by:
Hi all, I've been writing in ColdFusion for about 6 years now, and now that we've installed a Sharepoint Portal Server I'm finding that I need to use ASP.Net to make database calls. I'm finding...
12
by: motimh | last post by:
Could someone please show me the code (or design-time) required to use a comma-delimited textfile as data to a datagrid?
11
by: CM Manager via DotNetMonster.com | last post by:
I am very frustrated due to this exception error I am receiving. I've tried searching numerous user support groups, Microsoft Support Net, Google, etc. and haven't found exactly my situation....
3
by: ordit | last post by:
hey everybody!, Im new in the forum & to vb6. I want to connect a datagrid with the .datasource, .datamember prperties. my command requires a parameter: select order,name from tabe1 where...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.