473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Update a dataTable to DB

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

Jun 21 '06 #1
1 1647
you have to set the insertcommand and updatecommand of sqldataadapter.

"Niron kag" <Ni******@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
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

Jun 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
I'm using a DataTable in my application. I am able to load rows into the DataTable quickly. What's puzzling me, however, is that when I update a set of cells in the DataTable, the update is really...
8
by: ZeroVisio | last post by:
Hi, I want to know if there is an easy way to do update a column of a row in DataTable.
1
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
1
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
4
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
1
by: Tim Kelley | last post by:
I need to loop through a datatable and update a particular field. This seems like it should be fairly easy but it is giving me fits. Here is the code that I have so far. foreach (DataRow row...
4
by: Matteo Migliore | last post by:
Hi. I writed a method that takes two DataTable with same schema and return a third DataTable that: - insert new rows from "compare" DataTable - delete rows contained in "source" and not in...
0
jas16183
by: jas16183 | last post by:
Hi Guys, need some help here, Im working on a project in vb.net, the problem im facing is that my tableadapter.update(dataset.datatable) is not functioning, the datatable has a relation with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.