Greetings experts,
We have a database called Types that has two fields, TypeID, and Type Name.
Then we have a textbox called newType.
The idea of this textbox is that when a user attempts to select an item from the combobox and that item does not exist in the combobox, then enter the new item into the newType textbox and submit to the database.
Once submitted, it now becomes available for selection in the combobox.
Here is how I have approached this problem:
-
- SqlDataAdapter sda1 = new SqlDataAdapter("SELECT DISTINCT TypeId, TypeName FROM Types", constr);
-
- DataTable dt = new DataTable();
- sda1.Fill(dt);
-
-
- DataRow row = dt.NewRow();
- row[0] = 0;
- row[1] = "Please select member";
- dt.Rows.InsertAt(row, 0);
-
- txtType.DataSource = dt;
- txtType.DisplayMember = "TypeName";
- txtType.ValueMember = "TypeId";
- txtType.SelectedIndex = 0;
Once a value has been entered into the newType textbox field, I process it:
The problem is when I click submit to add the newType to the database, I am getting the following error message:
System.ArgumentException: No mapping exists from object type System.Data.DataRowView to a known managed provider native type.
at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen, Boolean streamAllowed)
Any ideas what I am doing wrong?
Thanks in advance