HappyProgrammer
Programmer
Hello,
I have a datatable which was populated from a flat file by looping through it adding 1 row at a time to the datatable. Once that is done the datatable is then bound to a datagridview for display on a form.
I would like to add an option to write the data to a sql server database. It would create a new table and create the fields based on the column names in the datatable. I know how to create a sql table and add columns based on the datatable and then insert records. When creating the columns in the sql table I would like to make them somewhat "smart". By "smart" I mean I would like to figure out what the maximum string length in each column is in the datatable and adjust the datatype in the sql table accordingly. ie. The max string length of column 1 is 260 the datatype becomes varchar(275), column 2 max length is 1200 and datatype becomes varchar(1300), etc. These numbers are just estimates but the amount of text in each column can vary considerably.
I am open to any suggestions. Maybe datatable isn't the way to go?
Thank you
I have a datatable which was populated from a flat file by looping through it adding 1 row at a time to the datatable. Once that is done the datatable is then bound to a datagridview for display on a form.
I would like to add an option to write the data to a sql server database. It would create a new table and create the fields based on the column names in the datatable. I know how to create a sql table and add columns based on the datatable and then insert records. When creating the columns in the sql table I would like to make them somewhat "smart". By "smart" I mean I would like to figure out what the maximum string length in each column is in the datatable and adjust the datatype in the sql table accordingly. ie. The max string length of column 1 is 260 the datatype becomes varchar(275), column 2 max length is 1200 and datatype becomes varchar(1300), etc. These numbers are just estimates but the amount of text in each column can vary considerably.
I am open to any suggestions. Maybe datatable isn't the way to go?
Thank you