Update a dataTable to DB

G

Guest

Hi,
I try to get a dataTable from the DB , add it a row and update it back to
the DB.
The program does not throw exception but the DB is not updated.
Can you please help me and tell me what I do wrong?
Thanks in advance!


public static void setOprjTableRow(string DBname , DataRow OPRJUpRow)
{
try
{
SqlConnection Conn = new SqlConnection("Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=" + DBname.ToString());
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand CMD = new SqlCommand("SELECT * FROM OPRJ" , Conn);
adapter.SelectCommand = CMD; SqlCommandBuilder builder = new
SqlCommandBuilder(adapter);
Conn.Open();
DataTable dtOprjAssc = new DataTable();
adapter.Fill(dtOprjAssc);
DataRow UpRow = dtOprjAssc.NewRow();
UpRow = OPRJUpRow;
dtOprjAssc.ImportRow(UpRow);
adapter.Update(dtOprjAssc);
dtOprjAssc.AcceptChanges();
Conn.Close(); } catch(Exception e)
{ Console.WriteLine(e.ToString());
}
finally
{ }
}// function
 
B

Balasubramanian Ramanathan

you have to set the insertcommand and updatecommand of sqldataadapter.
 

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