problem with INSERT INTO command

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 14
Reputation: devilz is an unknown quantity at this point 
Solved Threads: 0
devilz devilz is offline Offline
Newbie Poster

problem with INSERT INTO command

 
0
  #1
Feb 15th, 2009
Hello reader(s),

In table1 i have 3 columns named: emp_id, month, year. First i'm inserting emp_id from a recordset with validation from a text box. Problem is: In the same row i need to insert data of month and year column from individual text box.

Code should like:

insert into table1 (month, year) value ((textmonth.text), (textyear.text)) where table1(emp_id)=(textid.text)

I'm coding in VB 6.0 and very new with VB 6.0. can any one please help me with SQL code??
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: problem with INSERT INTO command

 
-1
  #2
Feb 15th, 2009
if your using adodb try this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. set rs as new adodb.recordset
  2. rs.open "Select * from table1 where emp_id='" & textid.text & "'", cn, 3, 3
  3. if rs.recourdcount > 0 then
  4. rs.open "insert into table1 (id, month, year) value ('" + textid.text + "','" + textmonth.text + "','" + textyear.text + "')", cn, 3, 3
  5. end if
  6. set rs = nothing
the cn there is your adodb.connection
if your using adodc just change the adodb to adodc, adodb to data1 if your using DAO. .

Regards,
Ryan Riel
Last edited by Ancient Dragon; Feb 15th, 2009 at 6:58 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 14
Reputation: devilz is an unknown quantity at this point 
Solved Threads: 0
devilz devilz is offline Offline
Newbie Poster

Re: problem with INSERT INTO command

 
0
  #3
Feb 16th, 2009
Dear Ryan,

Your code is working fine. I got another problem in one of my different INSERT command. the code is:

sql = "INSERT INTO DayWiseRoster (id) select UserOFTheMonth (id) where emp_id='" & txtempid.text & " ' "

This command prompting: DATA TYPE MISMATCHED.

Couldnt find what the problem is. I need such code for data validation. I guess passing integer value with reference of another integer value creates the problem. Is there any different SQL code for passing integer value.

the same command i used in my program for different table. That one is:

ssql=" INSERT INTO UserOfTheMonth (emp_id) SELECT users (Emp_id) where name='" & cboname.text & " ' "

Its working fine but the first one is creating problem. Can any one rid me of it??
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: problem with INSERT INTO command

 
0
  #4
Feb 17th, 2009
its created problem because they have the same entity

sql = "INSERT INTO DayWiseRoster (id) select UserOFTheMonth (id) where emp_id='" & txtempid.text & " ' "

id
id

try to change that. .
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1231 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC