Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old September 14th, 2003, 10:32 PM
aspuser25 aspuser25 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 141 aspuser25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
simple retrieving from access

hi

i am simply testing my connectivity using access with vb. i want to retrieve the name when the age is 31. i am pasting my code. a compilation error comes at statement "Dim rs As ADODB.Recordset" when i click to a select button(i just have a textbox and a button in my form). the error is :
USER-defined Tyoe not defined???

why is this so?


Private Sub select_Click()
Dim rs As ADODB.Recordset

' Open the Recordset.
Set rs = conn.Execute("SELECT name FROM Test WHERE age =
31", , adCmdText)
If Not rs.EOF Or rs.BOF Then
rs.MoveFirst
Text1.Text = rs![Name]
End If

rs.Close
Set rs = Nothing
End Sub

Reply With Quote
  #2  
Old September 14th, 2003, 11:01 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,827 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 22 h 57 m 29 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Do you have Microsoft ActiveX Data Objects as a reference to your program?

Reply With Quote
  #3  
Old September 14th, 2003, 11:04 PM
aspuser25 aspuser25 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 141 aspuser25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
yes i just added... and now error is coming in recordset..

i am unable to open the recordset... in asp with access i used to use as:
rs.Open "SELECT name FROM Test WHERE age = 31", dsn = "school"

but how do i do in vb with access?

any help?
thanks!

Reply With Quote
  #4  
Old September 14th, 2003, 11:30 PM
aspuser25 aspuser25 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 141 aspuser25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
i now changed my code as==>but still i am not able to execute ..its saying database test is already open???

Private Sub select_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test"

conn.Open

' Open the Recordset.
Set rs = conn.Execute("SELECT name FROM Test WHERE age = 31", , adCmdText)
If Not rs.EOF Or rs.BOF Then
rs.MoveFirst
Text1.Text = rs![Name]
End If

rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing

End Sub

Reply With Quote
  #5  
Old September 14th, 2003, 11:36 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
U had opened the table in your DB or your code program is running??

Reply With Quote
  #6  
Old September 14th, 2003, 11:41 PM
aspuser25 aspuser25 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 141 aspuser25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Unhappy

no i closed the database

Reply With Quote
  #7  
Old September 14th, 2003, 11:49 PM
aspuser25 aspuser25 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 141 aspuser25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
i also made the following changes:
Open the Internet Services Manager.
Edit the Properties of the application.
On the Directory Security tab, edit Anonymous Access and Authentication Control.
Edit the Account used for Anonymous Access.
In IIS 4.0, clear the Enable Automatic Password Synchronization check box.

In IIS 5.0, clear the Allow IIS to control password check box.

then also the same error is coming

Reply With Quote
  #8  
Old September 15th, 2003, 12:22 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
U can add some judge in the code:
if Conn.state=opened then
conn.close
endif

Reply With Quote
  #9  
Old September 15th, 2003, 12:34 AM
aspuser25 aspuser25 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 141 aspuser25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
already tried

pls see code below. this is gettin on my nerves..i cannot understand the problerm

i already tried what u said: it gives error=>
Private Sub select_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

' Open a connection.
Set conn = New ADODB.Connection

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test;Persist Security Info=false;"
If conn.State = opened Then
conn.Close operation is not allowed when object is not closed
End If
conn.Open

' Open the Recordset.
Set rs = conn.Execute("SELECT name FROM Test WHERE age = 31", , adCmdText)
If Not rs.EOF Or rs.BOF Then
rs.MoveFirst
Text1.Text = rs![Name]
End If

rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing

End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
If conn.State = adStateOpen Then 'Check the open state of the connection
conn.Close 'If it is open then close it
End If
'Set oConnection and rs to nothing to prevent memory leak problems
Set conn = Nothing
Set rs = Nothing
End Sub

Reply With Quote
  #10  
Old September 15th, 2003, 06:05 AM
saxtonj saxtonj is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 11 saxtonj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 32 sec
Reputation Power: 0
Try it like this

Private Sub select_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

' Open a connection.
Set conn = ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test"

conn.Open

'Set recordset
set rs.ActiveConnection = conn

' Open the Recordset.
rs.open "SELECT name FROM Test WHERE age = 31"

If Not rs.EOF Then
Text1.Text = rs.Fields(0)
End If

rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing

End Sub

Reply With Quote
  #11  
Old September 15th, 2003, 11:29 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,560 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 16 h 32 m 3 sec
Reputation Power: 640
Quote:
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test"

Is "test" the name of the database file, without an extension?

Do you have any error trapping enabled (on error resume next) that may be hiding some error messages?

Reply With Quote
  #12  
Old September 15th, 2003, 10:29 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
Yes! Doug G! U are right!
Data Source Must be a mdb filename.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > simple retrieving from access


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |