sql server - Visual basic express sql statements -
i'm programming software sql server 2014 , i'm stuck !
i'm trying use value list box insert sql query in order process query , result here code
private sub button1_click(sender system.object, e system.eventargs) handles button1.click if sql.hasconnection = true sql.runquery(" select '" & listbox1.selecteditem.tostring() & " ' test ") if sql.sqldataset.tables.count > 0 datagridview1.datasource = sql.sqldataset.tables(0) end if end if end sub
my issue displays surname on datagrid or firstname on datagrid when selected :/
i can't find problem please :/
i think if follows fix issue
private sub button1_click(sender system.object, e system.eventargs) handles button1.click if sql.hasconnection = true sql.runquery(" select [" & listbox1.selecteditem.tostring() & "] test ") if sql.sqldataset.tables.count > 0 datagridview1.datasource = sql.sqldataset.tables(0) end if end if end sub
the passed named being treated literal string, adding square brackets enforce sql server treat object name(column name in case).
Comments
Post a Comment