views:

48

answers:

1

So, I have a control with a datagrid in it and I was wondering if depending on the value I get back from the a Request.QueryString if I could set the table name to that (that is the value being sent) and then have it build the columns?

I have about 3 different tables, and they have different amounts of columns, and of course with different names.

+1  A: 

Hi,

Yes you need to access the QueryString collection to get the table name your passing in then just create a new datatable and set its name.

/Create the table and name it/

DataTable dt = new DataTable();

dt.TableName = Request.QueryString["VariableName"].ToString();

/add the columns/

dt.Columns.Add(Request.QueryString["VariableName"].ToString(), typeof(String)); dt.Columns.Add(Request.QueryString["VariableName"].ToString(), typeof(String)); dt.Columns.Add(Request.QueryString["VariableName"].ToString(), typeof(String));

Enjoy!

Doug
DataTable is not registering as a predefined type. I'm assuming it's something to do with my web.config. grr.
Justen
ok, got that. But there doesn't seem to be a Name for dt.Name. Closest thing is Namespace.
Justen
Hi Justin - You are correct its "TableName" - I apologize for the typo.
Doug
I'm a bit confused on how I actually bind the data from my DB to these new columns? I'm using MS SQL
Justen