[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

storing alpha-muneric Emp ID's to 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 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
khankejan
Asked:
khankejan
  • 4
2 Solutions
 
lttia1Commented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
well... easy money :-)
0
 
khankejanAuthor Commented:
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mayank SAssociate Director - Product EngineeringCommented:
Employee-ID is alphanumeric, right? So it needs the quotes here too.

>> where EmpID = " & txtEmpID.Text

would be:

where EmpID = '" & txtEmpID.Text & "' "
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Split between lttia1 and mayankeagle.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Please proceed with that recommendation.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now