.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

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
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 13th, 2003, 08:30 AM
Pain Pain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Sheffield, UK
Posts: 94 Pain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to Pain
OleDBDataAdapters

Hi guys

Im trying to produce a form that shows messages given certain criteria as defined in public variables previsouly in my vb code.

However, when i've tried to create my form using the dataadapter wizard, i've found that it doesnt like my pre-defined variables, and only pure SQL statements.

eg:

select * from emp where empID=" & MyEmpIdVar & ";
will cause error

select * from emp where empID=2;
wont cause error

any suggestions for a work around are kindly welcome!

Chris

Reply With Quote
  #2  
Old October 13th, 2003, 08:27 PM
oni9 oni9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Brisbane, Australia
Posts: 50 oni9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
"select * from emp where empID=" & MyEmpIdVar.ToString() & ";"

what is your MyEmpIdVar data type?

Reply With Quote
  #3  
Old October 14th, 2003, 12:23 AM
Watever Watever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 486 Watever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 20 sec
Reputation Power: 6
you could always try LIKE instead of = if you use any % or _ in your research.

or if it's not exactly in the same format.
__________________

Reply With Quote
  #4  
Old October 14th, 2003, 05:07 AM
Pain Pain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Sheffield, UK
Posts: 94 Pain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to Pain
Quote:
Originally posted by oni9
"select * from emp where empID=" & MyEmpIdVar.ToString() & ";"

what is your MyEmpIdVar data type?


Its numeric. I believe its something to do with the wizard itself, since I have the same code elsewhere on different forms and it works fine.

Thing is tho, I could always change it outside of the wizard screen, but the statement appears in that "windoze generated code" that im not allowed to touch.

Any one got other suggestions?

Reply With Quote
  #5  
Old October 14th, 2003, 10:07 AM
vinidel vinidel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Virginia
Posts: 19 vinidel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am not very sure but I have read in the book when using variables in the query in data adapter try with @variablename

Example:

Select * form tablename where (ProductName LIKE @productName + '%')

Reply With Quote
  #6  
Old October 14th, 2003, 10:35 AM
Pain Pain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Sheffield, UK
Posts: 94 Pain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to Pain
ok, there is a followup to this:

I've noticed that in the the commandtext within the data adapter brings you to a "query builder" styled screen.

If i enter my SQL statement by hand (it gives the option to build it for you), and i enter:

select * from emp where empNumber= " & myvar &";

it'll change it (after closing of course to make you think its done nothing wrong) to:

select * from emp where empNumber = ' & myvar & ';

Of course, running this will make it freak out, since the variable is incorrectly declared, so I try:

select * from emp where empNumber = ' " & myvar & " ';
to which it freaks at the number being the wrong data type.

I've checked the code as to seeing where it stores the SQL statement, and (conveniently) is held in the windows generated region, and hence non-touchable.

I also tried to manually change the sql statement (against advice from windows) and for the the initial run compilation, worked fine. There after, the SQL statement is erased, and we're back to square 1.

So. Suggestions anyone?

Reply With Quote
  #7  
Old October 14th, 2003, 07:30 PM
oni9 oni9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Brisbane, Australia
Posts: 50 oni9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I do touch the IDE generated code alot. It is touchable and changable as long as you know what you are doing.

I think I know what is wrong with your sql


if you just type
select * from emp where empID=" & MyEmpIdVar & ";
into the Command Text property box, it will be translated to
"select * from emp where empID="" & MyEmpIdVar & "";"
and when you run it, the sql text sent to OLEDB engine will be
select * from emp where empID=" & MyEmpIdVar & ";


you should (re-)assign the sql command text to your SqlCommand.CommandText in code view
syntax should be similar to
selectCmd.CommandText = "select * from emp where empID=" & MyEmpIdVar & ";"
so the command Text will be translated into:
"select * from emp where empID=2;"
the the sql text sent to OLEDB engine will be
select * from emp where empID=2;

(selectCmd should be the selection command which appears on your adapter's property)



However, often with an adapter, I would do it in other way, using parameters. And it is quite lengthy to show you how to do it, and I'm at work. So you might have to browse the "help", MSDN, or ask someone else.

Last edited by oni9 : October 14th, 2003 at 07:32 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > OleDBDataAdapters


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT