| | |
Trouble adding new row to DataTable (C#)
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Solved Threads: 0
I have been following this tutorial (http://msdn2.microsoft.com/en-us/lib...63(vs.80).aspx ) and so far everything has gone well. I am running Visual Studio 2005 and SQL Server 2005. I can run queries just fine. However, when I try to update (insert a new row), my Customers table in my SampleDatabaseDataSet will not commit any new changes.
I am using this documentation for adding rows: http://msdn2.microsoft.com/en-us/lib...34(VS.80).aspx
Here is my code:
When this runs, the form displays that the row was added correctly. However, after the program is finished executing, the data is not written to the table. The changes don't really commit. Any ideas? Thanks.
I am using this documentation for adding rows: http://msdn2.microsoft.com/en-us/lib...34(VS.80).aspx
Here is my code:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace TestApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SampleDatabaseDataSet.CustomersRow newCustomersRow = sampleDatabaseDataSet.Customers.NewCustomersRow(); newCustomersRow.CustomerID = "AABCD"; newCustomersRow.CompanyName = "AAA Works"; sampleDatabaseDataSet.Customers.Rows.Add(newCustomersRow); // Why won't these changes commit? customersTableAdapter.Update(newCustomersRow); sampleDatabaseDataSet.Customers.AcceptChanges(); customersBindingSource.EndEdit(); this.customersTableAdapter.Fill(this.sampleDatabaseDataSet.Customers); } } }
When this runs, the form displays that the row was added correctly. However, after the program is finished executing, the data is not written to the table. The changes don't really commit. Any ideas? Thanks.
Last edited by BoarderX; Jul 9th, 2007 at 3:00 pm.
•
•
Join Date: Jul 2007
Posts: 2
Reputation:
Solved Threads: 0
I have the same problem can someone help
here is the test code:
deletetable is two columns only
ACRM.deletetableDataTable table = new ACRM.deletetableDataTable();
DataRowCollection rc;
DataRow newRow;
rc = table.Rows;
newRow = table.NewRow();
newRow[1] = "hello";
rc.Add(newRow);
the code runs but nothin gets written .. what are we doig wrong?
here is the test code:
deletetable is two columns only
ACRM.deletetableDataTable table = new ACRM.deletetableDataTable();
DataRowCollection rc;
DataRow newRow;
rc = table.Rows;
newRow = table.NewRow();
newRow[1] = "hello";
rc.Add(newRow);
the code runs but nothin gets written .. what are we doig wrong?
•
•
•
•
I have been following this tutorial (http://msdn2.microsoft.com/en-us/lib...63(vs.80).aspx ) and so far everything has gone well. I am running Visual Studio 2005 and SQL Server 2005. I can run queries just fine. However, when I try to update (insert a new row), my Customers table in my SampleDatabaseDataSet will not commit any new changes.
I am using this documentation for adding rows: http://msdn2.microsoft.com/en-us/lib...34(VS.80).aspx
Here is my code:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace TestApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SampleDatabaseDataSet.CustomersRow newCustomersRow = sampleDatabaseDataSet.Customers.NewCustomersRow(); newCustomersRow.CustomerID = "AABCD"; newCustomersRow.CompanyName = "AAA Works"; sampleDatabaseDataSet.Customers.Rows.Add(newCustomersRow); // Why won't these changes commit? customersTableAdapter.Update(newCustomersRow); sampleDatabaseDataSet.Customers.AcceptChanges(); customersBindingSource.EndEdit(); this.customersTableAdapter.Fill(this.sampleDatabaseDataSet.Customers); } } }
When this runs, the form displays that the row was added correctly. However, after the program is finished executing, the data is not written to the table. The changes don't really commit. Any ideas? Thanks.
•
•
Join Date: Jul 2007
Posts: 2
Reputation:
Solved Threads: 0
The problem i my code was that I did not update the table adapter revised code that works is shown
ACRMTableAdapters.deletetableTableAdapter deletetable_TA = new ACRMTableAdapters.deletetableTableAdapter();
ACRM ACRM1 = new ACRM();
ACRM.deletetableRow newRow = ACRM1.deletetable.NewdeletetableRow();
newRow.test1 = "ALFKI3";
ACRM1.deletetable.Rows.Add(newRow);
deletetable_TA.Update(newRow);
I hope this helps someone
ACRMTableAdapters.deletetableTableAdapter deletetable_TA = new ACRMTableAdapters.deletetableTableAdapter();
ACRM ACRM1 = new ACRM();
ACRM.deletetableRow newRow = ACRM1.deletetable.NewdeletetableRow();
newRow.test1 = "ALFKI3";
ACRM1.deletetable.Rows.Add(newRow);
deletetable_TA.Update(newRow);
I hope this helps someone
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Solved Threads: 1
•
•
•
•
I have been following this tutorial (http://msdn2.microsoft.com/en-us/lib...63(vs.80).aspx ) and so far everything has gone well. I am running Visual Studio 2005 and SQL Server 2005. I can run queries just fine. However, when I try to update (insert a new row), my Customers table in my SampleDatabaseDataSet will not commit any new changes.
I am using this documentation for adding rows: http://msdn2.microsoft.com/en-us/lib...34(VS.80).aspx
Here is my code:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace TestApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SampleDatabaseDataSet.CustomersRow newCustomersRow = sampleDatabaseDataSet.Customers.NewCustomersRow(); newCustomersRow.CustomerID = "AABCD"; newCustomersRow.CompanyName = "AAA Works"; sampleDatabaseDataSet.Customers.Rows.Add(newCustomersRow); // Why won't these changes commit? customersTableAdapter.Update(newCustomersRow); sampleDatabaseDataSet.Customers.AcceptChanges(); customersBindingSource.EndEdit(); this.customersTableAdapter.Fill(this.sampleDatabaseDataSet.Customers); } } }
When this runs, the form displays that the row was added correctly. However, after the program is finished executing, the data is not written to the table. The changes don't really commit. Any ideas? Thanks.
![]() |
Similar Threads
- checkbox in datagridview c# (C#)
- Getting Current Row Values in the DataGrid control (ASP.NET)
- script problem adding to database (PHP)
- Trouble Adding A Notebook To A Routed Network (Networking Hardware Configuration)
Other Threads in the C# Forum
- Previous Thread: How to make a package from the project ?
- Next Thread: Calling TCL scripts from C#
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom data database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox serialization server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update upload usercontrol users validate validation visualstudio webbrowser windows winforms wpf xml





