DataAdapetr Update

G

Guest

Hi!

I have text file with tabbed columns, I am getting those values into a
dataset by parsing the tab. I want to save the same dataset into a table in a
database. I am getting error "Update requires a valid InsertCommand when
passed DataRow collection with new rows". I am using the following code

StreamReader s = new StreamReader(File);
string AllData = s.ReadToEnd();
string[] rows = AllData.Split("\r\n".ToCharArray());

//Now add each row to the DataSet
foreach (string r in rows)
{
//Split the row at the delimiter.
if (r != "")
{
string[] items = r.Split(delimiter.ToCharArray());
//Add the item
result.Tables[TableName].Rows.Add(items);
}
}
Database dbName = DatabaseFactory.CreateDatabase();
DbDataAdapter da = dbName.GetDataAdapter();
da.Update(result, "ProductsTest");

Thanks in advance.

Regards,
Bareb
 
W

W.G. Ryan - MVP

You don't have an Insert command associated with the adapter so it doesn't
know what to update - this could be b/c there's not a primary key on the
destination table (probably is).

Check the insert command that's generated on the GetDataAdapter command -
make sure it looks ok, field names match (column name may be different in db
than they are in table - in which case you'll need tablemappings and/or
columnmappings). Make sure you have a key on the destination table - nothing
autogenerated will work without it.

HTH,

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top