Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Datagridview column header to make use of column description in sql table

Posted on 2010-01-01
11
Medium Priority
?
658 Views
Last Modified: 2013-12-17
Hi, how can I display the description the columns in a SQL table to be the column header names in the datagridview? I'm using C# .NET Windows Forms. Thanks in advance.
0
Comment
Question by:0nepiece
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:namazikhah
ID: 26160940
would you describe more about what you want?
0
 

Author Comment

by:0nepiece
ID: 26160957
For example, in the datagridview, I want to display the column header name "Item Code" instead of "ItemCode". I'm not sure of this, but I placed the value "Item Code" in the description column in the SQL Server data table design. Is there a way that I could use that? Or maybe you have another method in mind?
0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 26160974
In the datagridview, there is a property to change the Column Name.. u can do in that itself.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 3

Expert Comment

by:namazikhah
ID: 26160986
yeap! rajeeshmca is right, you can use column name to add what you want
0
 

Author Comment

by:0nepiece
ID: 26161029
But what I want to happen is that when I bind the data table in the data grid, somehow the "column descriptions" from the SQL data table can be accessed shall be set as the headers of the the data grid views.
0
 
LVL 15

Assisted Solution

by:rajeeshmca
rajeeshmca earned 248 total points
ID: 26161061
Then what you can do is while retieving from the Database assign the Name that needs to shown as the Header like

select
   field1 as 'First Field',
   Field2 as 'Second Field'
from
 tablename

Now your grid will show the required thing
0
 

Author Comment

by:0nepiece
ID: 26161097
I updated my stored procedure and added the column descriptions, then refreshed my db connection and data adapter but it didn't display the column descriptions I added.
0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 26161131
can u plaese post ur storedprocedure
0
 

Author Comment

by:0nepiece
ID: 26161281
CREATE PROCEDURE dbo.ReadItemSearchGridView
(
      @ItemCode nvarchar(10),
      @ItemName nvarchar(30)
)
AS
      SET NOCOUNT ON;
SELECT     ItemCode 'Item Code', ItemName 'Item Name', ItemDesc, CategoryCode, StatusCode
FROM         ItemSearchGridView
WHERE     ItemCode LIKE ISNULL(@ItemCode,'%') OR ItemName LIKE ISNULL(@ItemName,'%')
GO
0
 
LVL 7

Accepted Solution

by:
aplusexpert earned 252 total points
ID: 26168831
Hi,


To do this you have two options.

1) first rename the columns names in select query.

2) Assign Header name values after bind the grid with data.

using

DataGrid.Column(0).HeaderText = "What you want".


Thanks.
0
 

Author Closing Comment

by:0nepiece
ID: 31671922
Thanks!
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question