M
Mervin Williams
My page includes a dataset with a dataadapter for the Contacts table, with
insert command that reads:
================================================================
INSERT INTO Contact
(firstname, lastname, title, phone)
VALUES (@firstname, @lastname, @title, @phone);
SELECT contact_id, firstname, lastname, title,
phone
FROM Contact
WHERE (contact_id = @@IDENTITY)
================================================================
I've configured an output parameter for this insert command (@contact_id)
that retrieves the autoincrement value for the contact_id column.
Nonetheless, the value of the output parameter is returning null after the
insert, although the value exists in the database.
Please help! Here is the data adapter update and parameter retrieval code.
================================================================
// Create new row object
dsCompanyInfo.ContactRow rowToInsert =
(dsCompanyInfo.ContactRow)dsCompanyInfo.Tables["Contact"].NewRow();
// Updates the dataset table.
rowToInsert.firstname = newFirstName;
rowToInsert.lastname = newLastName;
rowToInsert.title = newTitle;
rowToInsert.phone = newPhone;
dsCompanyInfo.Tables["Contact"].Rows.Add(rowToInsert);
Boolean hasChanges = dsCompanyInfo.HasChanges();
// Calls a SQL statement to update the database from the dataset
daContact.Update(dsCompanyInfo);
daContact.Fill(dsCompanyInfo);
if (daContact.InsertCommand.Parameters["@contact_id"].Value != DBNull.Value)
{
contactid =
(int)daContact.InsertCommand.Parameters["@contact_id"].Value;
}
================================================================
Mervin Williams
insert command that reads:
================================================================
INSERT INTO Contact
(firstname, lastname, title, phone)
VALUES (@firstname, @lastname, @title, @phone);
SELECT contact_id, firstname, lastname, title,
phone
FROM Contact
WHERE (contact_id = @@IDENTITY)
================================================================
I've configured an output parameter for this insert command (@contact_id)
that retrieves the autoincrement value for the contact_id column.
Nonetheless, the value of the output parameter is returning null after the
insert, although the value exists in the database.
Please help! Here is the data adapter update and parameter retrieval code.
================================================================
// Create new row object
dsCompanyInfo.ContactRow rowToInsert =
(dsCompanyInfo.ContactRow)dsCompanyInfo.Tables["Contact"].NewRow();
// Updates the dataset table.
rowToInsert.firstname = newFirstName;
rowToInsert.lastname = newLastName;
rowToInsert.title = newTitle;
rowToInsert.phone = newPhone;
dsCompanyInfo.Tables["Contact"].Rows.Add(rowToInsert);
Boolean hasChanges = dsCompanyInfo.HasChanges();
// Calls a SQL statement to update the database from the dataset
daContact.Update(dsCompanyInfo);
daContact.Fill(dsCompanyInfo);
if (daContact.InsertCommand.Parameters["@contact_id"].Value != DBNull.Value)
{
contactid =
(int)daContact.InsertCommand.Parameters["@contact_id"].Value;
}
================================================================
Mervin Williams