Hello, I am trying to display SQL query results in a GUI.

Right now I am displaying the information in a standard TextBox, but I would like to be able to sort by the different columns and stuff like that, much like if I had a excel spreadsheet open with the same information, except in a window on my GUI.

thanks in advance

Recommended Answers

All 14 Replies

Ever tried a DataGridView control?

could you point me in the direction of a tutorial? the C# documentation by microsoft is terrible

thanks so much, I'll see what I can do with this

Yes - here is one that is pretty straight forward for setting it up


now to be able to sort them make sure you have allowsorting = "true" in the html of the datagrid as well as sortexpression in the html: here is an example I have used

<asp:datagrid id="dgrdRequest" 
			    style="Z-INDEX: 100; LEFT: 88px; POSITION: absolute; TOP: 168px"
				runat="server" Width="616px" Height="96px" HorizontalAlign="Left" GridLines="Vertical" CellPadding="3"
				BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#999999" AutoGenerateColumns="False"
				AlternatingItemStyle-BackColor="#DCDCDC" HeaderStyle-ForeColor="#FFFFFF" HeaderStyle-Font-Bold="True"
				HeaderStyle-BackColor="#6600ff"  AllowSorting="True" tabIndex="5" 
                onsortcommand="dgrdRequest_SortCommand" >
					    DataField="RequestDate" SortExpression="RequestDate" HeaderText="Date Request Entered"
						<HeaderStyle Width="50px"></HeaderStyle>

Ok, I ran into a problem

I am trying to connect to a SQL Server database which apparently OleDbConnection can't do.

any way to get around this?

sure it can.

are you using mssql or mysql? or another variation?

ok now I'm just trying to use the DataGrid and DataSet with SqlConnection.

(using TSQL by the way)

so let me get this straight:

1.I run the query

2.create a temp table with the same columns that my select query contained

3. add the results of the query to the table

4. then bind the table to my DataGrid and display it

is that it?

Pretty much .. as long as you're just displaying

ok I have it working ok, and the sorting of the integer columns is working, but the sorting of the string columns is not working correctly.

I have this:

queryResultGrid.AllowSorting = true;

and this:

DataColumn prac_nm = new DataColumn("prac_nm", typeof(string));

when I try to sort it seems like it tries to sort them, it groups the simliar names together, but they arent in alphabetical order.

I thought that maybe I needed to change the datatype from typeof(string) to something else but everything I've tried has not worked.

Have you bound the columns as well? I've used:

	DataField="RequestDate" SortExpression="RequestDate" HeaderText="Date Request Entered" DataFormatString="{0:MM/dd/yyyy}">
		<HeaderStyle Width="50px"></HeaderStyle>

	DataField="PriorityName" SortExpression="PriorityID" HeaderText="Priority">
		<HeaderStyle Width="50px"></HeaderStyle>
		<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle>
		<FooterStyle HorizontalAlign="Left" VerticalAlign="Top"></FooterStyle>

also do you have the sort expression in the code?


Did that help?

I'm using C# so this dosen't really apply to me.

thank you for your response though

ah - I'm using C# as well but I thought you were using web forms instead of windows forms

Did you get your problem solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.