473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

DataGrid --- Showing SQL Columns

I have some code (below) to display the column information for a specified
SQL table. It works reasonably well, but when the grid displays it shows
the name of the table underlined and clickable. Clicking on the table name
shown in the grid expands the table to show all the rows and columns as I
want.

I realized that I needed to add the .Expand(-1) member to even show the
table name automatically. But what grid property do I set or invoke that
will just show the full table without the user having to click on the table
name?

TIA

Harry

String myQuery = "select * from syscolumns where id = object_id('" +
dbname.ToString() +

".." + tablename + "')";

SqlCommand myCommand = new SqlCommand(myQuery);

myCommand.Connection=sqlConnection1;

SqlDataAdapter da = new SqlDataAdapter(myQuery, sqlConnection1);

DataSet ds = new DataSet();

da.Fill(ds,tablename.ToString());

dataGrid1.DataSource=ds;

dataGrid1.Expand(-1);
Nov 15 '05 #1
2 1237
Harry, you need to set the DataSource and the DataMember properties for the
grid. It sounds like you are just setting the DataSource. The DataMember
should be the table name.

--
Greg Ewing [MVP]
http://www.citidc.com

"Harry Whitehouse" <ha***@envmgr.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
I have some code (below) to display the column information for a specified
SQL table. It works reasonably well, but when the grid displays it shows
the name of the table underlined and clickable. Clicking on the table name shown in the grid expands the table to show all the rows and columns as I
want.

I realized that I needed to add the .Expand(-1) member to even show the
table name automatically. But what grid property do I set or invoke that
will just show the full table without the user having to click on the table name?

TIA

Harry

String myQuery = "select * from syscolumns where id = object_id('" +
dbname.ToString() +

".." + tablename + "')";

SqlCommand myCommand = new SqlCommand(myQuery);

myCommand.Connection=sqlConnection1;

SqlDataAdapter da = new SqlDataAdapter(myQuery, sqlConnection1);

DataSet ds = new DataSet();

da.Fill(ds,tablename.ToString());

dataGrid1.DataSource=ds;

dataGrid1.Expand(-1);

Nov 15 '05 #2
Greg --

Right you are!

I needed this:

dataGrid1.DataSource=ds.Tables[tablename.ToString()];
Thanks for the assist!!

Harry


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
3
by: John E. | last post by:
I have a datatable that I am binding to a C# ASP.NET 1.1 web page datagrid. I also want to put an "Edit" column on the datagrid. However, whenever I use the following code, it puts the Edit...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
2
by: tshad | last post by:
I have a Datagrid that has no rows in it, but I want the title to show, and they aren't. Is there a way to make them visible even if the Datagrid is empty? Thanks, Tom
2
by: Ron L | last post by:
I am attempting to set up a datagrid that will 1) display a subset of data from a SQL Stored Procedure in a different order form how SQL returns it, and 2) display 3 of the columns using pulldowns....
4
by: Hexman | last post by:
I was going along fine in my test to see how to manipulate the DataGrid (dgTrans) and its columns. I have a single form with one DataGrid (dgTrans) on it. The code I have in my form load event...
4
by: cooltech77 | last post by:
Hi, I am trying to build the following functionality in the datagrid. I have a lot of columns in the datagrid which are being populated from the database and the user needs to scroll...
1
by: sp | last post by:
Hello I have a problem with the refresh performance in datagrid – when datagrid is being shown it is so slow that I can see one by one cells is drawn -datagrid contains about 35x40 of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.