Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > is there an option in visual studio to auto generate column name from sql column name
 

is there an option in visual studio to auto generate column name from sql column name

Is there an option in visual studio to auto generate column name from sql column name?

as is nowmy visual studio 200 8Standard Edition version 9.0.21022.8 RTM with .net 3.5 sp1 vc#
will generate datagridview DGV)from sql dataset with column nameslike datagridviewcolumnTextBox1,...datagridviewcolumntextboxN

It does get the datapropertyName correctly from sql column but sure it would bea lot more productive to allow develope to select an option globally or just at the time of generating DGV from sql dataset.

Right now I just don't know how to construct the datapropertydescriptor for bindingsource to retrive value. and itis counter clarity to use the currently auto-generated meaningless column names.

I have to manually do edit columns on the dgv to specify column name. If I forget, I willget error in run time trying to retrieve the DGV["columnName",i]
fs - new to w7  Friday, September 04, 2009 3:55 AM
Hi fs - new to w7,

As far as I know, there is no direct way to auto generate the column names, but we can set the column names programmatically before we do something with the DataGridView. This is a code snippet:
private void Form1_Load(object sender, EventArgs e)
{
    //Set the Name to DataPropertyName progrommatically.
    foreach (DataGridViewColumn col in this.dataGridView1.Columns)
    {
        col.Name = col.DataPropertyName;
    }
}
Let me know if this helps or not.
Aland Li

Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 7:37 AM
thank you, I went into the edit column of the data gridview to change the column one by one.

I sure hope they will make available the option to generate the column names with some user specified prefix before the names from the respective sql table
fs - new to w7  Tuesday, September 08, 2009 4:42 AM

You can use google to search for other answers

Custom Search

More Threads

• Quickly lock & unlock lots of fields for editing - best way/practice
• Exponential slow down in Datagrid binding
• Total Summary Field in Datagrid?
• View and what to bind to
• Is that a bug in DataGridView component?
• To update the Database with OleDb.OleDbDataAdapter
• DataGridView - How to log changes to a cell?
• Copy the Records from one Table to another Table
• How do I perform drag and drop reorder of rows
• How to bind enum to a combo box using Binding class