Saturday, 24 March 2012

Dynamically passing table name in select query in vb.net

Today I tried to pass table name dynamically to select query  as
 cmd = New OdbcCommand ("select * from '" & table_name & "' where id=" & i & "", con)


But it failed. then fortunately got the correct one....
cmd = New OdbcCommand("select * from [" & table_name & "] where id=" & i & "", con)


Similarly avoid single quotes while using number.
eg: use  id=" & i & "  instead  id=' " & i & " ' ,when id is number type.