Solved

storing alpha-muneric Emp ID's to database.

Posted on 2003-12-08
9
329 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

808 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