Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > General > Chit Chat > want to save Alpha-numeric employee ID in database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-03, 01:25
ishrat khan ishrat khan is offline
Registered User
 
Join Date: Oct 2003
Posts: 14
want to save Alpha-numeric employee ID in database

The problem is....I want to store Alpha-numeric Employee ID's in the database. When i stroe a numeric Employee ID like 001, 030 things went ok.... But when i try to enter Employee ID like " aa11 ", it is not saved to the database. And a vb error occurs.
The error number is : -2147217900
Description : The name " aa11 " in not permitted in this context. Only constants, experssions or variables allowed here. Column names are not permitted.
One thing more.... when i directly put some alpha-numeric ID in the data base .. there is no problem... But when i try to put with the vb6 interface forms the above mentioned error occurs....

Is there any wrong with my sql string that i had used in the vb6 application?

thanks for any urgent help... as my class assignment closing date is ahead.
Reply With Quote
  #2 (permalink)  
Old 12-09-03, 02:11
rokslide rokslide is offline
Coffee Minion
 
Join Date: Nov 2003
Location: Sydney
Posts: 1,515
you are using double quotes (or no quotes) instead of single quotes.... change to single quotes and all should be right witht he world.
Reply With Quote
  #3 (permalink)  
Old 12-09-03, 02:53
ishrat khan ishrat khan is offline
Registered User
 
Join Date: Oct 2003
Posts: 14
Re: want to save Alpha-numeric employee ID in database

Quote:
Originally posted by ishrat khan
The problem is....I want to store Alpha-numeric Employee ID's in the database. When i stroe a numeric Employee ID like 001, 030 things went ok.... But when i try to enter Employee ID like " aa11 ", it is not saved to the database. And a vb error occurs.
The error number is : -2147217900
Description : The name " aa11 " in not permitted in this context. Only constants, experssions or variables allowed here. Column names are not permitted.
One thing more.... when i directly put some alpha-numeric ID in the data base .. there is no problem... But when i try to put with the vb6 interface forms the above mentioned error occurs....

Is there any wrong with my sql string that i had used in the vb6 application? the string is ....
strsql = "INSERT INTO Employee(EmpID, Name) VALUES("
strsql = strsql & Me.txtEmpID.Text & "','"
strsql = strsql & Me.txtName.Text & "')"
conn.Execute strsql

thanks for any urgent help... as my class assignment closing date is ahead.
Reply With Quote
  #4 (permalink)  
Old 12-09-03, 18:40
rokslide rokslide is offline
Coffee Minion
 
Join Date: Nov 2003
Location: Sydney
Posts: 1,515
Is there any wrong with my sql string that i had used in the vb6 application? the string is ....

strsql = "INSERT INTO Employee(EmpID, Name) VALUES("


Should be....

strsql = "INSERT INTO Employee(EmpID, Name) VALUES('"

you are missing the first single quote in your post.
Reply With Quote
  #5 (permalink)  
Old 12-10-03, 06:28
ishrat khan ishrat khan is offline
Registered User
 
Join Date: Oct 2003
Posts: 14
thanks but another realted problem

I have placed the single quote and its works.... but the second part of the code that is an update statement doesnt work....
what i want to do is that when i update the salary of an employee a copy of the change is be saved in the SalMonth table as well. But i am facing problem in updating the employee s salary filed by using the following string.(*)


strsql = "INSERT INTO SalChange (EmpID, Salary, ChDate) VALUES('"
strsql = strsql & Me.txtEmpID.Text & "','"
strsql = strsql & Me.txtSalary.Text & "','"
strsql = strsql & Date & "')"
conn.Execute strsql


(*) strsql = "UPDATE Employee SET SalMonth = '" & txtSalary.Text & "' where EmpID = " & txtEmpID.Text
conn.Execute strsql

the error i got is...
err.number : -2147217913
Description : Syntax error converting the varchar value ' A-11 ' to a column of datatype int.
Reply With Quote
  #6 (permalink)  
Old 12-10-03, 18:18
rokslide rokslide is offline
Coffee Minion
 
Join Date: Nov 2003
Location: Sydney
Posts: 1,515
you have exactly the same problem....

this

Code:
strsql = "UPDATE Employee SET SalMonth = '" & txtSalary.Text & "' where EmpID = " & txtEmpID.Text

should be

Code:
strsql = "UPDATE Employee SET SalMonth = '" & txtSalary.Text & "' where EmpID = '" & txtEmpID.Text & "'"

(note the side quotes around the EmpID)

If you are building and sql statement with string values you need to wrap them in single quotes.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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