views:

230

answers:

1

I have a C# Winforms app that is connecting to a SQL Server 2005 database. The form I am currently working on allows a user to enter a large amount of different types of data into various textboxes, comboboxes, and a DataGridView to insert into the database. It all represents one particular type of machine, and the data is spread out over about nine tables.

The problem I have is that my DataGridView represents a type of data that may or may not be added to the database. Thus, when the DataGridView is created, it is empty and not databound, and so data cannot be entered. My question is, should I create the table with hard-coded field names representing the way that the data looks in the database, or is there a way to simply have the column names populate with no data so that the user can enter it if they like? I don't like the idea of hard-coding them in case there is a change in the database schema, but I'm not sure how else to deal with this problem.

+1  A: 

You could query the database for the names of the columns, if you're using a SqlDataReader you can use it's GetSchemaTable. Here's some sample code for doing this:

http://support.microsoft.com/kb/310107

ho1
Great! That's just what I needed. Thanks for your help.
Geo Ego