ck9663:
Try to do an insert on the table itself.
I'm not sure what you mean by "the table itself". I'm trying to modify a DataRow, but that row has already been added to the table (see code below). Here are the problems I've been having:
When I try to save a new (inserted) record via the following code:
- DataRow row = dataTable.Rows [currRec];
-
row.BeginEdit ();
-
-
// try { row ["ContactID"] = txtContactID.Text; }
-
// catch (Exception exc) { MessageBox.Show (exc.Message); }
-
-
row ["Title"] = txtTitle.Text;
-
row ["FirstName"] = txtFirstName.Text;
-
row ["MiddleName"] = txtMiddleName.Text;
-
row ["LastName"] = txtLastName.Text;
-
row ["Suffix"] = txtSuffix.Text;
-
row ["Phone"] = txtPhone.Text;
-
row ["EmailAddress"] = txtEmailAddress.Text;
-
-
row.EndEdit ();
-
-
try { dataAdapter.Update (dataSet, "Person.Contact"); }
-
catch (System.Runtime.InteropServices.ExternalException exc)
-
{
-
MessageBox.Show (exc.Message + "\n\nSystem.Runtime.InteropServices.ExternalException");
-
}
I get the following ExternalException message:
Cannot insert the value NULL into column 'PasswordHash', table 'AdventureWorks.Person.Contact'; column does not allow nulls. INSERT fails. The statement has been terminated.
When I uncomment
- try { row ["ContactID"] = txtContactID.Text; }
-
catch (Exception exc) { MessageBox.Show (exc.Message); }
and enter ContactID in my WinForm, I get the same ExternalException. With the above uncomment made, when I DON'T enter a ContactID, I get the following exception message:
Input string was not in correct format. Couldn't store <> in ContactID Column. Expected type is int32.
Or maybe that it's a sample DB so microsoft only allow read-only.
How can I tell? I looked at the table in SQL Server 2008 Management Studio Express, but I couldn't see anything pertinent.