Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

storing alpha-muneric Emp ID's to database.

Posted on 2003-12-08
9
Medium Priority
?
349 Views
Last Modified: 2010-08-05
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 an 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 something wrong with the sql string i am using to do the task. 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 solution to this problem.

0
Comment
Question by:khankejan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
9 Comments
 
LVL 2

Accepted Solution

by:
lttia1 earned 252 total points
ID: 9902415
Try this:

strsql = "INSERT INTO Employee(EmpID, Name) VALUES('"
    strsql = strsql & Me.txtEmpID.Text & "','"
    strsql = strsql & Me.txtName.Text & "')"
    conn.Execute strsql

It seems that you have a missing quote for the empid.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9902810
well... easy money :-)
0
 

Author Comment

by:khankejan
ID: 9911126
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 248 total points
ID: 9911551
Employee-ID is alphanumeric, right? So it needs the quotes here too.

>> where EmpID = " & txtEmpID.Text

would be:

where EmpID = '" & txtEmpID.Text & "' "
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10319089
Split between lttia1 and mayankeagle.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10936402
Please proceed with that recommendation.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question