Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 15th, 2009, 07:42 AM
Authorized User
Points: 88, Level: 1
Points: 88, Level: 1 Points: 88, Level: 1 Points: 88, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
Default problem with INSERT INTO command

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 the SQL code??

Please...
Reply With Quote
  #2 (permalink)  
Old February 15th, 2009, 09:50 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Quote:
Originally Posted by devilz View 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 the SQL code??

Please...
Since you already have the emp_id in the database, you can use the update query

update table1 set month=textmonth.text, year=textyear.text where emp_id=textid.text


Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old February 15th, 2009, 04:31 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Just to clarify, you should build and execute a string that looks like Shasur said. Something like

Code:
dim sSql as string
sSql = "update table1 set month=" & textmonth.text & ", year= " & textyear.text & "where emp_id= " & textid.text
if any of this field is string (that I hope that month and years would be), that data should be round with ' (like field='value')

And please don't use never and ever (even if you are learning) a table name like table1. How will you know what it represents in a few weeks???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
Reply With Quote
  #4 (permalink)  
Old February 16th, 2009, 06:00 AM
Authorized User
Points: 88, Level: 1
Points: 88, Level: 1 Points: 88, Level: 1 Points: 88, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
Default problem with INSERT INTO command


Dear gbianchi,

Really you help me a lot. Your code is working fine. I got another problem in one of my different INSERT command. the code is:

Code:
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:
Code:
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 you rid me of it?? Please...
Reply With Quote
  #5 (permalink)  
Old February 16th, 2009, 07:52 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

That a weird SQL (never so a select without a FROM, unless you are getting data from a function or a SP.)...

Anyway the problem is that emp_id is probably a number, and numbers doesn't go with '' around then.

The second works fine because name is probably a string and strings go surrounded by ''.

Remember to read internet and manuals, this problems should not arise if you look for what you need.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
Reply With Quote
  #6 (permalink)  
Old February 17th, 2009, 07:24 AM
Authorized User
Points: 88, Level: 1
Points: 88, Level: 1 Points: 88, Level: 1 Points: 88, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
Default problem with INSERT INTO command

Quote:
Originally Posted by gbianchi View Post
That a weird SQL (never so a select without a FROM, unless you are getting data from a function or a SP.)...

Anyway the problem is that emp_id is probably a number, and numbers doesn't go with '' around then.

The second works fine because name is probably a string and strings go surrounded by ''.

Remember to read internet and manuals, this problems should not arise if you look for what you need.

Dear gbianchi,

With your hints I able to learn the different types of code to pass integer value in SQL statements with reference of a integer value.
Code:
sql = "INSERT INTO DayWiseRoster (id) select UserOFTheMonth (id) where emp_id= " & clng(txtempid.text)


Is it a right code??

Kids need appreciation and guide. In programming world Iím a kid and highly eager to learn programming.

You really help me a lot.

regards
Reply With Quote
  #7 (permalink)  
Old February 17th, 2009, 08:45 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Looks ok now (but I still think the select need a from clause, unless you are using a weird database engine that understand it).

Did you try it??

There is a lot of learning from trial and error too.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Command using a querystring Andrew.Berry ASP.NET 2.0 Basics 1 September 27th, 2007 10:26 AM
hi problem on bulk insert command karthikc85 SQL Server ASP 1 November 8th, 2006 04:22 AM
hi problem on bulk insert command karthikc85 SQL Server 2005 2 October 18th, 2006 12:32 PM
Insert command rajanikrishna ASP.NET 1.0 and 1.1 Basics 0 April 3rd, 2006 09:47 AM
ASP Insert into command joshua_mccrea Classic ASP Databases 5 August 13th, 2003 11:35 PM



All times are GMT -4. The time now is 12:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.