Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help on vb6 datagrid and sql

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
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2009-05-04 : 05:27:14
you can try like:--
declare @Id int
set @Id=2
insert into tbl(Id) values(@Id)

malay
Go to Top of Page

sql167
Starting Member

10 Posts

Posted - 2009-05-04 : 05:30:39
Thanks for your quick reply.
Go to Top of Page

sql167
Starting Member

10 Posts

Posted - 2009-05-04 : 05:42:03
I have about 10 columns, which is the best way?
Go to Top of Page

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
Go to Top of Page

sql167
Starting Member

10 Posts

Posted - 2009-05-04 : 22:07:49
Thanks, I will try it.
Go to Top of Page

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 help

Dim sql As String

'sql = "INSERT INTO LINENUMBER (BATCHNUM, ENTRYNUM, DISTCODE, DES, REVACC, ACCDESC, AMT, PRNTCOMM, COMM, DISCNT) VALUES ("
sql = sql + "'" + txtBatchNum.Text + "', " <--textbox
sql = sql + "'" + txtEntryNum.Text + "', " <--textbox
sql = 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
Go to Top of Page

sql167
Starting Member

10 Posts

Posted - 2009-05-12 : 03:38:12
Anyone?
Go to Top of Page

sql167
Starting Member

10 Posts

Posted - 2009-05-12 : 21:18:39
I got it myself. thanks
Go to Top of Page

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 it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -