Solved

storing alpha-muneric Emp ID's to database.

Posted on 2003-12-08
9
327 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
  • 4
9 Comments
 
LVL 2

Accepted Solution

by:
lttia1 earned 63 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 62 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

777 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