• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

VB ADO sql question

I am trying to add a new record to a table, and I am using the following code:

strSql = "INSERT INTO Rooms (RoomNo, Capacity, Style, Extension) values ("
        strSql = strSql + "" + txtRoomNo.Text + ","
        strSql = strSql + " " + txtCapacity.Text + ","
        strSql = strSql + " ‘" + cboStyle.Text + "‘,"
        strSql = strSql + " " + txtExtension.Text + ")"
cm = New OleDbCommand(strSql, cn)

which results in the following string[as an example]:
INSERT INTO Rooms (RoomNo, Capacity, Style, Extension) values (500, 600, ‘Meeting‘, 456)

and i get "operation error: no value given for one or more required parameters"

Any help is appreciated... Thanks

-TB

0
soulfulcat83
Asked:
soulfulcat83
1 Solution
 
Arthur_WoodCommented:
change this:

strSql = strSql + "" + txtRoomNo.Text + ","
       strSql = strSql + " " + txtCapacity.Text + ","
       strSql = strSql + " " + cboStyle.Text + ","
       strSql = strSql + " " + txtExtension.Text + ")"


to this:

strSql = strSql + txtRoomNo.Text + ","
       strSql = strSql + " " + txtCapacity.Text + ","
       strSql = strSql + " '" + cboStyle.Text + "',"
       strSql = strSql + " " + txtExtension.Text + ")"


the field delimiter for Text fields is a single quote ('), no the  character. also the "" at the beginning is un-necessary.


AW
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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