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
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