1

I have a dataset called "titulos" and have 1 table there called "tb" with the columns with the name "titulo","titulo 2" and "titulo3". I'm trying to do an insertion of rows in the event onclick of a button but for some reason my code doesn't work! My dataset is on a xsd file and I am using visual studio 2013 with c#. I already tried this code but I don't know how to apply in my situation:

NorthwindDataSet.CustomersRow newCustomersRow = 
northwindDataSet1.Customers.NewCustomersRow(); 
newCustomersRow.CustomerID = "ALFKI"; 
newCustomersRow.CompanyName = "Alfreds Futterkiste"; 
northwindDataSet1.Customers.Rows.Add(newCustomersRow);

The problem is that shows an error saying it does not recognize the dataset... The erros is : "The name " Ds_Admissibilidade" does not exist in the current context

  • you have a dataset called "titulos" and have 1 table there called "tb" with the columns with the name "titulo","titulo 2" and "titulo3", where are you adding rows in your code here? – Kryptonian Aug 30 '15 at 18:05

2 Answers2

0

A DataSet is a disconnected copy of the data. It forgets if the data originated from database, an xml file or anything else. When you add rows to the DataSet, you only change the in-memory copy, not the original source.

You need some mechanism to update the source. For databases, a table adapter or dataadapter will do this for you. For a file source, you need to serialize the DataSet to the file, much the reverse of the way you read in in first place.

Alireza
  • 5,421
  • 5
  • 34
  • 67
0

Hope this helps :)

        DataRow newRow = titulos.Tables["tb"].NewRow();
        newRow["titulo1"] = "titulo1";
        newRow["titulo2"] = "titulo2";
        newRow["titulo3"] = "titulo3";

        titulos.Tables["tb"].Rows.Add(newRow);

Make sure you're setting all the values of the non nullable parameters. If you're using another instance of the dataset "titulos" use ImportRow instead of Add function.

  • Is it a compile or a runtime error? If it's a compile error, is your code in the same namespace as the dataset? Sorry, but without an example of the code where the error is happening, it's kind of hard to understand your error. – Kate Batista Aug 31 '15 at 21:52