Reply
Need help, using VB 2005 Express and Access
Old 10-05-2007, 08:01 AM Need help, using VB 2005 Express and Access
Junior Talker

Posts: 4
Name: ALINA
Ok, bear with me, this must be obvious to someone but I can not get it.

I'm writing an application in Visual Basic 2005 Express, and in my project I have an Access database added (.mdb) and the dataset (.xsd). What I need to do is in some functions I'm writing, retrieve information from a Table in said database, and I'm sure there must be some easy built-in functions for doing this but I don't know them.

For example for a constructor:


Code:

Public Sub New(ByVal intID As Integer) intClassVariable = some data from the table retrieved using the ID parameter


The ID parameter being the ID on the Table of course.

So how do I accomplish this? I noticed I can declare objects as DataSets...do I need to set a 'DataSet' object to refer to the .xsd part of my project?

thanks in advance
_________________
bat control free windows registry cleaner
REDEN is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 10-05-2007, 04:26 PM Re: Need help, using VB 2005 Express and Access
Skilled Talker

Posts: 97
Name: Ganesh
Reden,

Here is the basic code for a Windows Application, Modify that to your need.

If you can be more specific, I can easily convert that for you:

Please substitute the database file location.

Code:
 
Imports System.Data.OleDb
Public Class Form1 Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e as _
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_
Data Source=C:\emp.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from table1", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
' loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @ www.vtrip.info
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 10-05-2007, 08:50 PM Re: Need help, using VB 2005 Express and Access
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,024
Name: Forrest Croce
Location: Seattle, WA
Quote:
Originally Posted by REDEN View Post
Public Sub New(ByVal intID As Integer) intClassVariable = some data from the table retrieved using the ID parameter


The ID parameter being the ID on the Table of course.

So how do I accomplish this? I noticed I can declare objects as DataSets...do I need to set a 'DataSet' object to refer to the .xsd part of my project?
sri_gan's answer is a pretty thorough starting point.

You can create a typed dataset from the xsd, and set it's select command to the sql you would use to get the data. You could do this one row at a time, by ID, if the table is very large, or all at once, or some set of rows you think you might need. Which one you want depends on how you'll use the code ... it's faster to read one row than a whole table, but it's faster to read a bunch of rows all at the same time than slow by slow.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Reply     « Reply to Need help, using VB 2005 Express and Access
 

Thread Tools

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.44352 seconds with 12 queries