473,508 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Db Connection and DataGrids

27 New Member
Hi all,

I'm have issues with my DB connection and the use of DataGrids.

My DB connection is through my web.config file and the sub looks as follows:

[HTML]sub OpenDatabase()

sysConn = ConfigurationSettings.AppSettings("SystemConnectio n")

sysDatabase = server.createobject("ADODB.connection")
sysDatabase.open(sysConn)

end sub[/HTML]

This me sub for my DataGrid:

[HTML]Sub BindData()

sysConn = ConfigurationSettings.AppSettings("SystemConnectio n")

objCmd = New OleDbCommand("SELECT top 10 * FROM tbl_ACCO_EU_Contacts", sysDatabase)

sysDatabase = server.createobject("ADODB.connection")

sysDatabase.open(sysConn)

objRdr = objCmd.ExecuteReader()

dbcontacts.DataSource = objRdr

dbcontacts.DataBind()

objRdr.Close()

End Sub[/HTML]

Where am I going wrong?

Cheers
adz
Aug 31 '07 #1
3 1026
dip_developer
648 Recognized Expert Contributor
Hi all,

I'm have issues with my DB connection and the use of DataGrids.

My DB connection is through my web.config file and the sub looks as follows:

[HTML]sub OpenDatabase()

sysConn = ConfigurationSettings.AppSettings("SystemConnectio n")

sysDatabase = server.createobject("ADODB.connection")
sysDatabase.open(sysConn)

end sub[/HTML]

This me sub for my DataGrid:

[HTML]Sub BindData()

sysConn = ConfigurationSettings.AppSettings("SystemConnectio n")

objCmd = New OleDbCommand("SELECT top 10 * FROM tbl_ACCO_EU_Contacts", sysDatabase)

sysDatabase = server.createobject("ADODB.connection")

sysDatabase.open(sysConn)

objRdr = objCmd.ExecuteReader()

dbcontacts.DataSource = objRdr

dbcontacts.DataBind()

objRdr.Close()

End Sub[/HTML]

Where am I going wrong?

Cheers
adz
are you creating the command object before opening the connection..?? as your code suggests...............

I think no problem in the code otherwise if connection and other stuffs are ok.
Aug 31 '07 #2
adz1809
27 New Member
are you creating the command object before opening the connection..?? as your code suggests...............

I think no problem in the code otherwise if connection and other stuffs are ok.
This is the code at the moment:

[HTML]Sub BindData()

opendatabase()

objCmd = New OleDbCommand("SELECT top 10 * FROM tbl_ACCO_EU_Contacts", sysConn )

objRdr = objCmd.ExecuteReader()

dbcontacts.DataSource = objRdr

dbcontacts.DataBind()

objRdr.Close()

End Sub[/HTML]

And I'm getting this error:

Server Error in '/AccoEndUser' Application.
--------------------------------------------------------------------------------

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

[HTML]Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 55: opendatabase()
Line 56:
Line 57: objCmd = New OleDbCommand("SELECT top 10 * FROM tbl_ACCO_EU_Contacts", sysConn )
Line 58:
Line 59: objRdr = objCmd.ExecuteReader()


Source File: C:\Websites\Acco_EndUser\record_srch.aspx Line: 57[/HTML]

Any help geratly needed.

Cheers

Adz
Aug 31 '07 #3
adz1809
27 New Member
This is the code at the moment:

[HTML]Sub BindData()

opendatabase()

objCmd = New OleDbCommand("SELECT top 10 * FROM tbl_ACCO_EU_Contacts", sysConn )

objRdr = objCmd.ExecuteReader()

dbcontacts.DataSource = objRdr

dbcontacts.DataBind()

objRdr.Close()

End Sub[/HTML]

And I'm getting this error:

Server Error in '/AccoEndUser' Application.
--------------------------------------------------------------------------------

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

[HTML]Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 55: opendatabase()
Line 56:
Line 57: objCmd = New OleDbCommand("SELECT top 10 * FROM tbl_ACCO_EU_Contacts", sysConn )
Line 58:
Line 59: objRdr = objCmd.ExecuteReader()


Source File: C:\Websites\Acco_EndUser\record_srch.aspx Line: 57[/HTML]

Any help geratly needed.

Cheers

Adz
All sorted, here is the finished code:

[HTML]Sub BindData()

dim dsn As String = ConfigurationSettings.AppSettings("SystemConnectio n")

dim objConn as New OleDbConnection(dsn)

objCmd = New OleDbCommand("SELECT top 10 * FROM tbl_ACCO_EU_Contacts", objConn )

objConn.open()

objRdr = objCmd.ExecuteReader()

dbcontacts.DataSource = objRdr

dbcontacts.DataBind()

objRdr.Close()

End Sub[/HTML]
Aug 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
416
by: ree32 | last post by:
I have a placeholder and depending on a user input(a drop downlist) when the user clicks a button I dynamically create a number of datagrids and fill them with data from a database. But the problem...
0
1245
by: Scott Meddows | last post by:
I'm having trouble scrolling some datagrids so they sync up... I have two identical datagrids on a form, filled with eh same dataset. I want a user to be able to scroll on the datasets and the...
4
1584
by: | last post by:
Hello. In SQL Server Query Analyzer, if I type in, say, 2 select queries, it returns 2 datagrids of results, with a scrollbar on the right to scroll between the 2 (or more) datagrids. I wanted to...
2
1312
by: tjonsek | last post by:
I've been reading most of the day on how to use datagrids and came up with code to delete a record. I'm getting an error "Object Reference not set to an instance of an object" for the line where I...
3
1968
by: Mark Wiewel | last post by:
hi all, i am a newbie in ASP.NET and i couldn't find the solution to this one: i have a form with three datagrids on it. i would like to align them vertically with a space between each grid of...
0
771
by: Cindy | last post by:
Hello. Where do I find the actual connection string and dataset query in the HTML files, so that I can edit by making it a parameter query? Is this something I have to do manually -- write the...
7
1834
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table...
3
1479
by: Sankalp | last post by:
Currently I am developing a advanced VB 2005 application which Display's/ Updates / (Creates New ) data in the database. For this purpose I am using databound controls, i.e. all my datagrids,...
2
1915
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.