select table to show using textbox

ss123

Member
Joined
Feb 25, 2006
Messages
14
Programming Experience
1-3
Hi, if i want to use a input box that prompt user to key in the table name and show that data in data grid.
I have try this but can't work, so is there any alternatives?
i assign the value get from the input box to Myalue. Then i using the select query: select date, number from MyValue; i also try select date, number from '" & MyValue & "' .... both also can't work..
besides that, if i key in the table name without input box, it works but i cannot include open attribute but if i put * then all attribute can show include open attribute.
Anyone can advise me on this? the code is like below:
VB.NET:
Dim myValue As String
' message = "Enter a stock name"
'title = "InputBox Demo"
'defaultValue = "Maxis"
 
'myValue = InputBox(message, title, defaultValue)
'If myValue Is "" Then
myValue = "Maxis"
OleAdapt = New OleDb.OleDbDataAdapter("Select * from '" & myValue & "'", ConOleDB)
OleAdapt.Fill(DsAllStock, "'" & myValue & "'")
DataGrid1.DataSource = DsAllStock.Tables("'" & myValue & "'")
DataGrid1.CaptionText = "Record No." & DataGrid1.CurrentRowIndex + 1 & " of 0" & DsAllStock.Tables("'" & myValue & "'").Rows.Count
 
Last edited by a moderator:
I apologise if i'm speaking out of turn here, but i think that this could be done a more elegant way. It's just because i dont like inputboxes really. I'd rather see all the table names in a nice listbox/listview or even a combobox. I know that this doesn't really solve your problem. Also check out parameterised queries, they are more stable, and make for easier reading.
 
Back
Top