Use Replace and placeholder for table name:
Dim cmdText2 As String
cmdText2 = "SELECT * FROM XTABLEX "
and later replace
cmdText2 = cmdText2.Replace("XTABLEX", strTableName)
where strTableName is obtained from the user (or dropdown box)
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
Ok. You had cmdText2 = "SELECT * FROM XTABLEX" in class declaration and it gave you that error. Dim cmdText2 as String = "SELECT * FROM XTABLEX" works in class declaration?
To get it to work in application you have to have some function/sub where to do replacing. Is this possible? You mentioned dropdown box:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
'
' Get table name from dropdown box, build SQL and...
Dim strSQL As String
strSQL = cmdText2.Replace("XTABLEX", strTableName)
' Use strSQL
End Sub
Can you use it in this way?
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
Yeah Yeah... Thanks a lot . I did exactly that before you posted your reply. Thanks anyways , your first post gave me a head start. Thanx a lot . appreciate it.
Now i have a different problem regarding SQL scripts. may be you could help me out with that one. I have posted the question on Wed Development -> Databases -> MS SQL. Would be of great help if you could help me out.
Thanx again for every thing. Appreciate it.
Ok, see http://www.daniweb.com/forums/post700670.html#post700670
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203