| Author |
Topic |
|
sql167
Starting Member
10 Posts |
Posted - 2009-05-04 : 05:15:41
|
| I have a vb6 datagrid and a save button which allow user input in run time and save to sql table with the save button. My problem is that I don't know how to name the datagrid column in the sql statement. i.e. .execute ("insert into tablename (table columns) values (datagrid columns). Thanks. |
|
|
malaytech2008
Yak Posting Veteran
95 Posts |
Posted - 2009-05-04 : 05:22:27
|
| Try once.. use proper quotation inside the statement.execute ("insert into tablename (table columns) values ('+datagrid columns+').malay |
 |
|
|
malaytech2008
Yak Posting Veteran
95 Posts |
Posted - 2009-05-04 : 05:27:14
|
| you can try like:--declare @Id intset @Id=2insert into tbl(Id) values(@Id)malay |
 |
|
|
sql167
Starting Member
10 Posts |
Posted - 2009-05-04 : 05:30:39
|
| Thanks for your quick reply. |
 |
|
|
sql167
Starting Member
10 Posts |
Posted - 2009-05-04 : 05:42:03
|
| I have about 10 columns, which is the best way? |
 |
|
|
malaytech2008
Yak Posting Veteran
95 Posts |
Posted - 2009-05-04 : 08:20:48
|
| When use stored procedure and then pass the values of ten column as parameter in the SP.for this use second case where in insert statement pass the parameter of the SP to the insert stmt.or when you want to pass parameter from application level;use insert stmt and pass the column values directly to the insert stmt.malay |
 |
|
|
sql167
Starting Member
10 Posts |
Posted - 2009-05-04 : 22:07:49
|
| Thanks, I will try it. |
 |
|
|
sql167
Starting Member
10 Posts |
Posted - 2009-05-10 : 23:34:41
|
| I am not sure whether this is exactly what you have suggested but I have tried this and I get "variable not defined" for the column names in datagrid. Please helpDim sql As String'sql = "INSERT INTO LINENUMBER (BATCHNUM, ENTRYNUM, DISTCODE, DES, REVACC, ACCDESC, AMT, PRNTCOMM, COMM, DISCNT) VALUES ("sql = sql + "'" + txtBatchNum.Text + "', " <--textboxsql = sql + "'" + txtEntryNum.Text + "', " <--textboxsql = sql + "'" + DISTCODE + "', "<--Error(I beleive it is the same for the rest of column names)sql = sql + "'" + DES + "', "sql = sql + "'" + REVACC + "', "sql = sql + "'" + ACCDESC + "', "sql = sql + "'" + AMT + "', "sql = sql + "'" + PRNTCOMM + "', "sql = sql + "'" + COMM + "', "sql = sql + "'" + DISCNT + "') "testcn.Execute |
 |
|
|
sql167
Starting Member
10 Posts |
Posted - 2009-05-12 : 03:38:12
|
| Anyone? |
 |
|
|
sql167
Starting Member
10 Posts |
Posted - 2009-05-12 : 21:18:39
|
| I got it myself. thanks |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-05-14 : 02:07:18
|
quote: Originally posted by sql167 I got it myself. thanks
Post the working code so that others can know itMadhivananFailing to plan is Planning to fail |
 |
|
|
|