The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
error in vb script 
Posted: 22 Apr 07 10:08 AM
|
fiogf49gjkf0d Dear all
I am trying in to insert values in to the new table which i created under account table
I am trying to insert values in to this table but it is giving error like give values for every field in the table which you created in the data base . i am only giving the values to fields(create user, account id, modify user )which i created in the table but how can i pass the values to the default fields
The code i have written is as shown below
Sub SaveClick(Sender) Dim objSLXDB 'Dim objRS Set objSLXDB = New SLX_DB
strSQL = insert into Documents_Submitted values("+ComboBox1.Text+"','"+Picklist1.Text")
objSLXDB.ExecuteSQL strSQL
End Sub
the form has two ctrls combo box and picklist , user select values from combo box( i am populating this comco with acocunt names) and picklist and he will click save button that should got saved in data base
I feel shame because even i am not getting how to insert the values in to table but i tried for retrieve data i am getting it even i tried for deletion i am getting it but i am not getting how to insert
Any body pls help me in this issue
with regards vamsi
|
|
|
|
Re: error in vb script 
Posted: 22 Apr 07 4:43 PM
|
fiogf49gjkf0d If you are typing in the code exactly as you have it.. then you are missing some single quotes and another quote at the end... strSQL = insert into Documents_Submitted values('" + ComboBox1.Text + "','" + Picklist1.Text + "')"
The two fields that will hold the values from combobox1.text and picklist1.text need to be the first two fields in the table. I mean litterally.
This is why I always specify my field names. Always. OK not always, but I mean to 
strSQL = "insert into Documents_Submitted (fieldname1, fieldname2) values ('" & ComboBox1.Text & "','" & Picklist1.Text & "')"
This way if you specify them out of order or the dba adds a field by recreating the table (or creates it with his own script) then you will still be OK.
*edited SQL to fix + to & for vbscript |
|
|
|
Re: error in vb script 
Posted: 23 Apr 07 2:29 AM
|
fiogf49gjkf0d Originally posted by Vamsi
Dear all
I am trying in to insert values in to the new table which i created under account table
I am trying to insert values in to this table but it is giving error like give values for every field in the table which you created in the data base . strSQL = insert into Documents_Submitted values("+ComboBox1.Text+"','"+Picklist1.Text")
|
|
Unless you specify which fields you are writing the values into, SQL will expect values for all the fields on the table. Instead use the following syntax:
INSERT INTO DOCUMENTS_SUBMITTED (ACCOUNTID, CREATEUSER) VALUES (("+ComboBox1.Text+"','"+Picklist1.Text")
This SQL statement (assuming that there are no other required fields on this table (such as a "DOCUMENTS_SUBMITTEDID") should work.
If you are populating every field on the table, then you could get away without listing the fields that you are writing to, but it is against best practices. For instance, lets say that there were only 2 columns on the table, and that your SQL statement does work. You write several applications that read/write against that table, and then several years down the road someone else adds a new column to the Table. Now every single SQL Insert statement will break. You will have to revisit every application to correct the situation (Granted, if you added the file you probably would like to change all applications to incorporate the new field, however you would have a limited change window because the SQL statements will actually fail).
|
|
|
| |
|
Re: error in vb script 
Posted: 23 Apr 07 11:01 AM
|
fiogf49gjkf0d INSERT INTO DOCUMENTS_SUBMITTED (ACCOUNTID, CREATEUSER) VALUES (("+ComboBox1.Text+"','"+Picklist1.Text")
This SQL statement (assuming that there are no other required fields on this table (such as a "DOCUMENTS_SUBMITTEDID") should work.
|
|
I am pretty sure the missing + and single quotes would cause it to fail as well  |
|
|
|
Re: error in vb script 
Posted: 23 Apr 07 11:34 AM
|
fiogf49gjkf0d Originally posted by Jason Huber
I am pretty sure the missing + and single quotes would cause it to fail as well  |
|
Next time I will check my syntax before posting, as indeed you are right. I cut and paste his code into mine, but the Purpose of my code was to demonstrate to him the fact that he was not listing the Fields into the SQL statement.
|
|
|
|
Re: error in vb script 
Posted: 23 Apr 07 12:11 PM
|
fiogf49gjkf0d Originally posted by Raul A. Chavez
the Purpose of my code was to demonstrate to him the fact that he was not listing the Fields into the SQL statement.
|
|
As was my initial post. I try and follow that rule in production code as well. Good advice.
We could have added: dont try and use + in vbscript (it is used to add things up - weird for C# guys) Use parameterized queries (you know ? instead of "'" & something & "'" etc)
but the main point was to specify the fields. |
|
|
|