Solved

storing alpha-muneric Emp ID's to database.

Posted on 2003-12-08
9
322 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:mayankeagle
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle 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:mayankeagle
ID: 10319089
Split between lttia1 and mayankeagle.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10936402
Please proceed with that recommendation.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 76
for loop with Set 4 45
VB6 Compile Compatibility Issue 4 35
index Out OF Range Exception error 4 31
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now