0

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??

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by ryan311
-1

if your using adodb try this

set rs as new adodb.recordset
rs.open "Select * from table1 where emp_id='" & textid.text & "'", cn, 3, 3
if rs.recourdcount > 0 then
rs.open "insert into table1  (id, month, year) value ('" + textid.text + "','" + textmonth.text + "','" + textyear.text + "')", cn, 3, 3
end if
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

Comments
After 125 posts, I expect you would know how to use code tags.
0

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??

0

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. .

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.