views:

45

answers:

1

Hi, I have written some logic in C#. Now I need to update it to the already created Dataset. The Dataset is containing a Table PackageTable. It has two fields, PackageId, and PackagePrice Now, I want to search the table for certain Packageid, say 'P1' and update the PackagePrice with a new value , say '100'.

Please tell me how to do it with C#. Please also note that I am not updating it using a textbox or gridview etc. Thanks in advance

+1  A: 

You can try this

dt.Select("PackageId = 1")[0]["PackagePrice"] = 2;

dt is your data table, select the rows from it, then set the field value to what you require.

From comments, small example

Dim dt As New DataTable
dt.Columns.Add("t")
Dim r As DataRow
r = dt.NewRow
r("t") = "aa"
dt.Rows.Add(r)

DataGridView1.DataSource = dt

Dim d As DataTable
d = DataGridView1.DataSource
TextBox1.Text = d.Rows(0)("t")
astander
thanks astander...but what is [0] in this?
404ram
Select returns an array of DataRow. [0] would be the first row in the array.
astander
also what is Select? It says'Dataset doesnt contain definition for 'Select''
404ram
Select is used from a Data Table
astander
@astender, but i dont want to create a new DataTable, I already have a dataset as dataset.xsd and it has the DataTable named Package already. Excuse me if the question is silly, I am new to ASP.Net thanks
404ram
The sample shows how to get the datatable from the DataGridView. Dim d As DataTable d = DataGridView1.DataSource
astander
Select is an Extension method (Fx 3.5).
Henk Holterman