VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
Go Back  Xtreme Visual Basic Talk > > > VB.NET code to open a table in an Access database in my project


Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2010, 02:19 PM
garethmann garethmann is offline
Centurion
 
Join Date: Jul 2003
Location: Fort Lauderdale, Florida
Posts: 105
Default VB.NET code to open a table in an Access database in my project


Hi,

Relatively new to VS.NET but I understand ASP and VbScript very well in Dreamweaver. I have an ASP.NET web application, I already have an Access database added to the project under the App_Data folder. I am already connecting to it to bind data to a listbox.

But now I want to write som VB code to connect to another table in the database from within a function. How do I do this? In my old DreamWeaver ASP applications I would have typed:

Code:
dim sSQL
dim sDir
Dim con   
Dim rst
			  
 'connect to database:
sDir = server.MapPath(".") 
					
Set con = Server.CreateObject("ADODB.Connection")
				
' open the Access data source with the Connection object
sConString = "Provider=Microsoft.Jet.OLEDB.4.0; " _						   & "Data Source=" & sdir & "\myDatabase.mdb"
							   
con.Open sConString
					
sSql = "Select * From MyTable'"
					
set rst = con.execute(sSql)
The thing that I am confused about is that the database is already added to the project and is being used to bind data to a listbox, so is there a simpler way to connect to the database from the VB Code?

Also, I have looked online and it says to add a reference to System.Data and then type "Imports System.Data" at the top of my VB Code (which would be the top of Default.aspx.vb). But another online example says to type <%@ Import Namespace="System.Data.OleDb" %> at the top of my HTML page (which would be the top of Default.aspx.vb).

So where should I be importing system.data? At the top of my aspx.vb page or at the top of my aspx page? And do I even need to import System.data? I was able to bind the listbox to the Access table before having any "Imports" command...
__________________
"Any sufficiently advanced technology is indistinguishable from magic."
Arthur C. Clarke
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
 
VB.NET code to open a table in an Access database in my project
VB.NET code to open a table in an Access database in my project
 
-->