473,761 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# - FORM: DataAdapter.Upd ate() doesn't work :(

2 New Member
Hello,

I wrote a little program to understand the ADO.NET's mechanism. It's a common program with a datagrid, textboxes and a toolstripbar with usually buttons. The problem is that meanwhile i add rows to dataset the save button works when i remove some of them the update method doesn't work.

Please see the following code:

public Popola()
{
InitializeCompo nent();
string connstring = "Data Source = .\\SQLEXPRESS; Initial Catalog = scuola; Integrated Security = True";
conn = new SqlConnection(c onnstring);

myset = new DataSet("Classe ");

myadapter = new SqlDataAdapter( "SELECT * FROM Classe ORDER BY IDClasse ASC", conn);
myadapter.Table Mappings.Add("T able", "Classe");
myadapter.Fill( myset);

da2 = new SqlDataAdapter( "SELECT * FROM Studente ORDER BY Cognome ASC", conn);
da2.TableMappin gs.Add("Table", "Studente") ;
da2.Fill(myset) ;

DataColumn colMaster1;
DataColumn colDetail1;
colMaster1 = myset.Tables["Classe"].Columns["IDClasse"];
colDetail1 = myset.Tables["Studente"].Columns["IDClasse"];
relClasStud = new DataRelation("R elClasStud", colMaster1, colDetail1);
myset.Relations .Add(relClasStu d);
myset.EndInit() ;

dsView = myset.DefaultVi ewManager;
.......
cm_clas = (CurrencyManage r)this.BindingC ontext[dsView, "Classe"];
cm = (CurrencyManage r)this.BindingC ontext[dsView, "Classe.RelClas Stud"];
}

//Remove and Save buttons code:
private void Remove_Click(ob ject sender, EventArgs e)
{

DataRowView rw_ = (DataRowView)cm .Current;
DataRow rw = rw_.Row;
myset.Tables["Studente"].Rows.Remove(rw );
cm.EndCurrentEd it();
//myset.AcceptCha nges();
cm.Position = 0;
textBoxPosition .Text = String.Format(" Record {0} of {1}", (cm.Position + 1), cm.Count);
}

private void btnSalva_Click( object sender, EventArgs e)
{
conn.Open();

SqlCommandBuild er sqlcmd = new SqlCommandBuild er(da2);
SqlCommandBuild er sqlcmd1 = new SqlCommandBuild er(myadapter);
da2.Update(myse t.Tables["Studente"]);
myadapter.Updat e(myset.Tables["Classe"]);
conn.Close();

}

Can you help me? T.T
Regards.
Pietro.
Sep 19 '07 #1
1 2132
Pietro Ova
2 New Member
Ok.. I resolve it!

Just replace the lines:
Expand|Select|Wrap|Line Numbers
  1.     myset.Tables["Studente"].Rows.Remove(rw);
  2.    cm.EndCurrentEdit(); 
  3.  
with:
Expand|Select|Wrap|Line Numbers
  1.       rw.Delete();
  2.  
Thanks anyway.
Pietro.
Sep 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4266
by: hch | last post by:
dataAdapter.Update(data, "TableName") won’t work! I was about to deploy my first website on the Internet only to discover that the dataAdapter.Update() throws the Server Error in the third underline. It was working fine before. ConnectionString in Web.config: ----------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <configuration>
6
1579
by: Geoff Pennington | last post by:
I have a class method that returns a DataAdapter. I want to access the table(s) contained in the DataAdapter. Of course, accessing the DataSets would be good enough, because I could get the tables from there. I can't find a way to do this. Am I missing something? Much obliged.
16
453
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub in the Parent form and reference a child mdi form like this: Sub ReadText()
13
2089
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an OleDbCommand with an SQL String and the connection it has a DataAdapter with the command then it fills the DataSet's DataTable with the streamed data.
9
1467
by: cherishman | last post by:
When I use self-defined database, sometimes the dataadapter can't auto create insertcommand, updatecommand and deletecommand, it just only create selectcommand? But when I use these database such as Pub or Northwind in SQL Server to create dataadapter, it can auto create updatecommand and deletecommand. Why?
3
8933
by: RSH | last post by:
Hi, I have a situation in where i have two instances of SQL server, the first is our Production Environment, the second is our Development environment. Both servers contain the same databases but I need to write a utility that can transfer a row of data from the Production to the Development servers. I wrote the code below, which doesn't error...but it doesn't work...no data is updated. This is very odd because I can see that both of...
1
1383
by: Franklin M. Gauer III | last post by:
In VS2003 I used to be able to drag a SQL Server table from Server Explorer onto my webservice (in design mode) and it would automatically create a DataAdapter for me. This doesn't work in VS2005 anymore (crap) - is this by design? Does anyone know? Now if you create a DataAdapter in VS2005 (on a webservice project) it generates the SQL statements and puts them in a .RESX file (i.e. the UPDATE and INSERT SQL command text). Then the...
6
14000
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection = conn da.UpdateCommand.CommandText = "Update tbl1 set fld1 = 'test' where ID = 1" da.Update(tblx) '--tblx/tbl1 not getting updated here.
0
9336
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.