this sql statement is killing me - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

this sql statement is killing me

chillimousechillimouse Posts: 59Member
ok here it is i am trying to insert all of the data from a form into a SQL server database.
i am using visual basic 6

here is the statement i am trying to do
cmdemployee.CommandText = "INSERT INTO employees ('fname,midname,lname,address,ssn,city,state,zip,extention,employeeid,
ethnicity,sex,religion,hiredate,dateofbirth') Values ('" & strfname & ", " & strmidname & ", " & strlname & ", " & straddress & ", " & strssn & ", " & strcity & ", " & cbbstate & ", " & strzip & ", " & zipext & ", " & rstotal & ", " & strhphonearea & ", " & strwphonearea & ", " & strhphone & ", " & strwphone & ", " & email & ", " & stremploymentstat & ", " & strethnic & ", " & strsex & ", " & strrelig & ", " & strhiredate & ", " & birthdate & "')"

ok now i have tried this about a million ways and this is how i have it right now.
the error i am getting is
"invalid object name 'employees'"

now i have another part of the form that is pulling information from this database and same table so it isn't in the connection because i am using the same connection string.
also as you notice i have single quotes areound the columns and the values this is because when i apss a variable into the values column i have to use the syntax
commandname.commandtext = "Insert into tablename ('columns) VALUES ('" & variable1 & "')"
now if i have the single quote in just the values list visual basic thinks that i have one more variable than i have columns.

if anyone can help me with this one i would greatly appreciate it
please email me with your suggestions

[email protected]

thanks again


  • owen1owen1 Posts: 76Member
    why are there single quotes around the colmns in the insert statement?

    INSERT INTO employees ('fname,midname,lname,address,ssn,city,state,zip,extention,employeeid,
    ethnicity,sex,religion,hiredate,dateofbirth') Values

    there should be no single quotes in this part like this

    INSERT INTO employees (fname,midname,lname,address,ssn,city,state,zip,extention,employeeid,
    ethnicity,sex,religion,hiredate,dateofbirth) Values
    check out my current projects:

Sign In or Register to comment.