Home:ALL Converter>C# Winforms ADO.NET - DataGridView INSERT starting with null data

C# Winforms ADO.NET - DataGridView INSERT starting with null data

Ask Time:2010-05-04T00:36:46         Author:Geo Ego

Json Formatter

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.

Author:Geo Ego,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/2759586/c-sharp-winforms-ado-net-datagridview-insert-starting-with-null-data
yy