Click here to Skip to main content
15,503,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, the datatable dtTableFields has two column.
ID and name
The table in the database has name of length 5

I get an error on this line:
newRow["Name"] = "<-- Select a value -->";

and ofcourse it complains of the size.

How can I modify the code below without changing the width size of the field in the table in the database please?
private void PopulateFieldNames()
            DataTable dtTableFields = TableFieldsGet(strSomeName);

            DataRow newRow = dtTableFields.NewRow();

            newRow["Name"] = "<-- Select a value -->";

            dtTableFields.Rows.InsertAt(newRow, 0);

            cboTableFields.DisplayMember = "Name";
            cboTableFields.ValueMember = "ID";
            cboTableFields.DataSource = dtTableFields;

            cboTableFields.SelectedIndex = 0; 

1 solution

Check the value of the following:


You can change it if you need to, however remember that if you're going to save the data back to a database, you'll have to make sure that the column width is truncated to fit the database column. Otherwise, you'll get an error when you try to save.
Share this answer
arkiboys 17-Oct-11 7:39am    
Many thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900