Solved

DataControl.RecordSource= How to pass a SQL to MSSQL Server 6.5??

Posted on 1998-06-24
4
149 Views
Last Modified: 2010-05-03
I have recently upsized the back end of my app from Access 97 to MSSQL Server 6.5. One DataControl originally has the following statement:
Data1.RecordSource="SELECT * FROM Staff WHERE StaffID='" & txtStaffID.Text & "'"
Data1.Refresh
However, it does not work with MSSQL Server 6.5 since it goes thru the ODBC layer. I read from "Help" and know that I can set the RecordSource = QueryDef.some_kind_of_property
to pass the SQL statement and then do the Refresh. But how??? Can anyone give me an example???
0
Comment
Question by:ppmb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1464208
The code you have will work.  You have another problem.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1464209
Let me clarify.

Your original code:
Data1.RecordSource="SELECT * FROM Staff WHERE StaffID='" & txtStaffID.Text & "'"

Is fully acceptable, even when you go through an ODBC layer.

Are you sure txtStaffID.Text contains data?
Are you sure the tables were rebuilt in SQLServer the same as they were in Access (table and field names the same)?

Are you getting any errors?

0
 
LVL 2

Accepted Solution

by:
Jagar earned 70 total points
ID: 1464210
If StaffID is an Autonumber field then take out the single quotes it should read
Data1.RecordSource="SELECT * FROM Staff WHERE StaffID= " & txtStaffID.Text

Like everyone said this SQL statement will work, but this looks to be your problem not the statement itself.
0
 

Author Comment

by:ppmb
ID: 1464211
I read the comments from expert clifABB first and found out that it really is not the problem from the statement. Instead, it is from setup and the DBA. I am gonna credit clifABB the points but clifABB didn't have an answer for me to give points. How am I gonna do this???
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question