943,884 Members | Top Members by Rank

Ad:
Feb 15th, 2009
0

problem with INSERT INTO command

Expand Post »
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??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
devilz is offline Offline
14 posts
since Jan 2009
Feb 15th, 2009
-1

Re: problem with INSERT INTO command

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
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Feb 16th, 2009
0

Re: problem with INSERT INTO command

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??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
devilz is offline Offline
14 posts
since Jan 2009
Feb 17th, 2009
0

Re: problem with INSERT INTO command

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. .
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: condition not working under do loop
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Winsock Sending problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC