1 Replies - 6238 Views - Last Post: 07 May 2008 - 01:24 AM Rate Topic: -----

#1 pandeeswari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-May 08

Execute Query in Access using VB

Post icon  Posted 06 May 2008 - 11:44 PM

sir,
Hello, I would like to execute a query using Visual basic .
Please any one help me
Is This A Good Question/Topic? 0
  • +

Replies To: Execute Query in Access using VB

#2 anand_the_great  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 15-April 08

Re: Execute Query in Access using VB

Posted 07 May 2008 - 01:24 AM

Hello.

This is easy and good for you and everyone.

Remember to add a referennce for ADO, that is go to "Projects", Select "References", and Select
"Microsoft Active X Data Object 2.0 Liabrary". That's all. We good programmers hate DATAENVIRONMENT.

This is how you call the database, make sure it is in the same folder of your program.
Set the database in DataGrid, Obviously to add of one.
Dim con As ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
	Set con = New ADODB.Connection
	Set rs = New ADODB.Recordset
	rs.CursorLocation = adUseClient
	con.ConnectionString = _
			"Provider=Microsoft.Jet.OLEDB.4.0;" & _
			"Data Source=" & App.Path & "\wage.mdb"
	con.Open
	rs.Open "SELECT * From Water", con, adOpenDynamic, adLockOptimistic
	rs.MoveFirst
	Set DataGrid1.DataSource = rs
	'Command1.Caption = "Addd"
	'Command2.Caption = "Saveit"
End Sub



Here is a of MILLION-DOLLAR attempt to select a database table or any other conditions you can use.
THIS IS HARDCORE PROGRAMMING.
Dim sql, mysql As String
	Set con = New adodb.Connection
	Set rs = New adodb.Recordset
	rs.CursorLocation = adUseClient
	con.ConnectionString = _
			"Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\wage.mdb"
	con.Open
	mysql = "SELECT * From " & A										  'using a string to open a table
	rs.Open mysql, con, adOpenDynamic, adLockOptimistic
	rs.MoveFirst


Similarly, you can insert value of textboxes, list.List, combobox.Text, Label.caption and others.

Please have the curtasy to reply. (Applies to all of users).
Thank You.
Anand_The_Great
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1