0

I have a SQL Server table that has no rows. Programmatically in WinForms C#, I have created a DataTable with the same schema and populated it with data. I would then like to write the contents of this DataTable to the SQL Sever table using a SQLDataAdapter. Since the data adapter requires at least a SELECT statement, I've coded it like this:

using (SqlDataAdapter oAdapter = new SqlDataAdapter("SELECT * FROM invoice", oConnection))
{
    oAdapter.Fill(oDT);
    oAdapter.Update(oDT);
}

The trouble with this is that there are no rows returned because the SQL Server table is empty! So it seems the Fill and Update are working with no data, but I know my DataTable has over 7000 rows which I would like saved to the SQL Server table. Obviously, I'm doing something wrong, but I haven't been able to come across anything with a Google search like "SqlDataAdapter update empty SQL Server table" or similar phrases. It's probably a simple solution, so I'm hoping someone out there can tell me what it is. :) Forgive me if I've posted this in the wrong forum. TIA

Edited by dvongrad: Spelling and clarification

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by dvongrad
0

Thanks for the response. I used SqlCommandBuilder to auto generate the statement and all is well. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.