SELECT textBox1.Text FROM TableName;
Here is the code I have now.
private
void doQuery_Click(object sender, EventArgs e){
sqlDataAdapter1.SelectCommand.CommandText =
"SELECT" + textBox1.Text + "FROM TableName";dataSet1.Clear();
sqlDataAdapter1.Fill( dataSet1,
"TableName" );dataGrid1.SetDataBinding( dataSet1,
"TableName");But this isnt working. Can someone please tell me how to complete this code. It would be much appreciated.

Database Question
shaper
Try this mod:
private void doQuery_Click(object sender, EventArgs e)
{
sqlDataAdapter1.SelectCommand.CommandText =
"SELECT" + textBox1.Text + "FROM TableName";dataSet1.Clear();
sqlDataAdapter1.Fill( dataSet1,
"TableName" );//dataGrid1.SetDataBinding( dataSet1, "TableName");
dataGrid1.DataSource = dataSet1.Tables["TableName"];
dataGrid1.DataBind();
I am assuming this code is used in an ASP.NET Web Form. If it is in a Windows From you do not need the 'dataGrid1.DataBind();' call because it is automatic.
-David Sandor
smcandrew
Here is my code:
private
void button1_Click(object sender, EventArgs e){
sqlDataAdapter1.SelectCommand.CommandText =
"SELECT" + textBox1.Text + "FROM TabelName";dataSet1.Clear();
sqlDataAdapter1.Fill( dataSet1,
"TabelName" );dataGrid1.SetDataBinding( dataSet1,
"TableName").When I input * into the textbox, the SQL Server reads:
SELECT * FROM TabelName
And that works, and displays the tabel, but when I input a certain column it doesnt work. When I put "AuthorID", (SELECT AuthorID FROM TabelName) it doesnt work, and doesnt display the tabel.
Can you tell me any suggestions.
Bill Bickford
RobertLB
"SELECT " + textBox1.Text + " FROM TableName";
Note the spaces after the SELECT and before the FROM. From your code example you would end up with something like this:
SELECTCOLUMNAMEFROM TableName which is not valid SQL.
Amit.Nayar
Your SQL string needs to be
"SELECT " not
"SELECT"
Again notice the space after the "T" and before the ' " '.
And also
" FROM" not
"FROM"
Your SQL statement is invalid. Your database doesn't understand the command "SELECTAuthorIDFROM" but it will understand "SELECT AuthorID FROM".
duda65607
-David Sandor
Brendon123
And I just thought I would add another way to do it as well, with you of course as my inspiration.
private
void button1_Click(object sender, EventArgs e){
sqlDataAdapter1.SelectCommand.CommandText =
"SELECT" + " " + textBox1.Text + " " + "FROM TabelName";dataSet1.Clear();
sqlDataAdapter1.Fill(dataSet1,
"TabelName");dataGrid1.SetDataBinding(dataSet1,
"TabelName");}
Sorry for not understand your first answer.