C# - Updating Rows In DataTable?

Nov 22, 2010

I'm trying to update fields in a DataTable. The field I'm trying to edit is a date, I need to format it.

foreach (DataRow row in dt.Rows)
{
string originalRow = row["Departure Date"].ToString(); //displays "01/01/2010 12:00:00 AM"
row["Departure Date"] = DateTime.Parse(row["Departure Date"].ToString()).ToString("MM/dd/yyyy");
string newRow = row["Departure Date"].ToString(); //also displays "01/01/2010 12:00:00 AM"
}

How come this isn't getting updated?

View 2 Replies


Similar Messages:

DataSource Controls :: Adding Rows And Updating Tables From Datatable

Mar 7, 2010

Maybe this could be a simple questino, but for me it's difficult to do this action: I have a table in sql server 2005 with some records stored, for example 10 records. The primary key of this table, let's call it "Employee", it's a number field with an autoincrement constraint. I want to store more data into the table by using a OdbcDataTable object and OdbcDataAdapter and adding new rows to the datatable and afeter that use the "Update" method from the OdbcDataAdapter object.

The big deal is this: let's suppose that I want a add a new record to the datatable object, using any method or code sequence that you want. if I have 10 records stored on the data base table, when I retrieve this table schema by using the OdbcDataAdapter "Fill" method, I have a copy of the data base table schema in the DataTable object, right?. if I add a new row on the datatable object, it's suppose that the primary key column of that table must AUTO-INCREMENT the value of the key, I mean if the last value that I store on the table was the number 10 on the PK field, when I add a new row on the datatable object, the PK value on the datatable object must be the number 11 if the autoincrement constraint is present into the DataTable object, but in my case, it doesn't work

So, How can I define the conditions or set the c# data objects properties to wor in that way???. In this moment the PK column on the odbcDataTable doesn't auto-increment its value when I add a new row on it.

Please helpe with this.

PD: I have another question about the DataTable object, how many records can store this object?? I have some problems with this because sometimes when I use the Fill() method to get data into the DataTable or a DataSet object there's no problem if the Fill() method retrieves about 142000 records, but when I retrieve over the 145000 records, when I inspect the DataSet or DataTable object by using the debuging mode, they have null value. Any of you can tell me why this situation ocurrs??

View 1 Replies

DataSource Controls :: How To Select Rows From A DataTable And Create A New ViewList With The Selected Rows Only, While ...

May 31, 2010

I have one big DataTable with X rows. I want to select Y rows from it and bind them to a new ViewList. While doing it, I want to delete these rows from the DataTable (Having X - Y rows).

What is the best and fast way to do it?

I don't know if it is better to create a new DataTable to have the Y and after that bind them to a ViewList or something else?

I'm also looking for example in code how to select/delete rows from DataTable.

View 1 Replies

ADO.NET :: Find Rows In One DataTable From Another DataTable And Remove Them

Sep 9, 2010

I have a DataTable of available time slots. I have another DataTable of reserved time slots. I need to remove from the list of available slots the ones that have been reserved. The blocks are in 15 minute increments, but one of my problems is that the reservation can be longer than 15 minutes. I've had some luck removing one or two, but not all of the required columns.

Here's my code (it doesn't work right now).

[Code]....

View 1 Replies

Updating DataGrid Binded To Custom DataTable?

Mar 20, 2010

I bind custom DataTable to DataGrid through ObjectDataSource, where i use SelectMethod and UpdateMethod. SelectMethod working great, but when I try to update row it's breaking by MissingMethodException. What should i do to fix this problem?

View 1 Replies

Javascript - Avoid Page Flickering When Updating A YUI DataTable?

Sep 7, 2010

I am using jlinq a library for extending linq to json and hence i filter my json data. Consider i have a json data that draws a yui datatable on page load with 100 rows. I am doing a clientside filter which will reduce my json data and i am now redrawing the same datatable. What happens is it works pretty well but with an annoying flickering effect...

I call the below method from onkeyup event of the filter textbox,

[Code]....

View 2 Replies

Forms Data Controls :: GridView Updating Having Datasource Datatable?

Jul 16, 2010

I am making shopping cart application.On Viewing Shopping Cart,when i try to update the quatity of product column it permit me to edit but wn i click update link.the gridview disappears wid all products.send me some code snippet in C# as i want only quantity column to be editable.I am using the following code:in Code behind File

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;

[code]...

View 4 Replies

C# - Sum Selected Rows In Datatable Only ?

Aug 11, 2010

I have a datatable which has an amount column & a status column.I want to sum only those rows who have status '1'. How to do this ?I am summing the column via datatable Compute method.

View 1 Replies

Updating Only Changed Rows Using GridView Control?

Feb 9, 2011

what is the best way of updating to db only the changed rows using gridview?i have a gridview control that has inline editing and when the user edit the row there are two options "Update" or "Cancel" so user might just click update button without really updating the row...how can i make sure that, user really changed the row?

View 2 Replies

How To Keep The Rows Ordering Of Datatable Unchanged

Jul 6, 2010

I have a datatable with the ordering of its DataClassIndex column before editting:

DataclassIndex 0 1 2 3 4

When I start modifying some other cells in this datatable, the ordering of DataClassIndex column changes to something like this

DataclassIndex 3 4 2 1 0

How can I modify a datatable content without altering the original order of the datatable.

View 3 Replies

Datagrid With 2 Columns That Have Different Datatable Rows?

Feb 9, 2010

i want to make a datagrid with 2 columns and many rows the columns i want to have databinding with a datatable

i want the 1 row 1 column of datagrid have data from 1 row of datatable
i want the 1 row 2 column of datagrid have data from 2 row of datatable
i want the 2 row 1 column of datagrid have data from 3 row of datatable
i want the 2 row 2 column of datagrid have data from 4 row of datatable
......
......

i use something like this

[code]...

but i have two times the same in tha datagrid left and right

View 28 Replies

C# - How To Select Top Of Rows From A Datatable/dataview

May 7, 2010

How to select top n rows from a datatable/dataview in asp.net.currently I am using the following code by passing the table and number of rows to get the records but is there a better way.

public DataTable SelectTopDataRow(DataTable dt, int count)

{
DataTable dtn = dt.Clone();
for (int i = 0; i < count; i++)
{
dtn.ImportRow(dt.Rows[i]);
}
return dtn;
}

View 2 Replies

Export DataTable To CSV File - More Than 65,536 Rows

Mar 1, 2010

Exporting DataTable data to CSV file. It is working fine as expected as long as the export records are less than 65,536. When the records are more than 65,536 , only 65,536 records are shown in CSV file (remaing records are not shown). When the export is done(with more than 65,536 records), opening the file shows below message window. File is not loaded completely. When the Ok button is selected, below text displayed...

This message can appear if: You are trying to open a file that contains more than 65,536 rows or 256 columns. To fix this problem, open the source file in a text editor such as Microsoft Word. Save the source file as several smaller files that conform to this row and column limit, and then open the smaller files in Excel. If the source data cannot be opened in a text editor, try importing the data into Microsoft Access, and then exporting subsets of the data from Access to Excel. You are trying to paste tab-delimited data into an area that is too small. To fix this problem, select an area in the worksheet large enough to accommodate every delimited item.

Notes: You can not configure Excel to exceed the limit of 65,536 rows and 256 columns. By default, Excel places three worksheets in a workbook file. Each worksheet can contain 65,536 rows and 256 columns of data, and workbooks can contain more than three worksheets if your computer has enough memory to support the additional data. Solution:- Seems like here is the suggested solution. But it takes ages to export and show data. An export is done about 15mins ago, still it is doing that. Has anyone managed to find/resolve this issue?

[Code]....

View 4 Replies

DataTable Doesn't Store New Rows?

Mar 16, 2010

In my simple starter asp page I create a DataTable and populate it with two rows. The web site allows users to add new rows. My problem is the DataTable doesn't save the information. I've stepped through the code and the row gets added but the next time a row is added it's not there, only the original two and the newest one to get entered.

I have gotten around this, in an inelegant way, but am really curious why the new rows are being saved.

My code:

protected void Page_Load(object sender, EventArgs e)
{
_Default.NameList = new DataTable();
DataColumn col = new DataColumn("FirstName", typeof(string));
_Default.NameList.Columns.Add(col);
col = new DataColumn("LastName", typeof(string));
_Default.NameList.Columns.Add(col);
DataRow row = _Default.NameList.NewRow();
row["FirstName"] = "Jane";
row["LastName"] = "Smith";
_Default.NameList.Rows.Add(row);
row = _Default.NameList.NewRow();
row["FirstName"] = "John";
row["LastName"] = "Doe";
_Default.NameList.Rows.Add(row);
}
protected void AddButton_Click(object sender, EventArgs e)
{
DataRow row = _Default.NameList.NewRow();
row["FirstName"] = this.TextBox1.Text;
row["LastName"] = this.TextBox2.Text;
_Default.NameList.Rows.Add(row);
_Default.NameList.AcceptChanges(); // I've tried with and without this.
}

I've tried saving them to GridView control but that seems like quite a bit of work. I'm new to ASP.Net but have done windows programming in C# for the last two years.

View 3 Replies

C# - Check Whether Datatable Contains Any Matched Rows?

Aug 11, 2010

I am using Compute for summing up a datatable which has a condition. Sometimes, there are no rows inside the datatable matching my criteria so I get an exception on ComputeObject cannot be cast from DBNull to other types.Is there a way to check/filter the datatable to see if it has the desired rows, if yes only then I apply Compute.

total = Convert.ToDecimal(CompTab.Compute("SUM(Share)", "IsRep=0"));

View 2 Replies

Looping Through A Returned Rows In DataTable

Jul 31, 2012

I have as script that runs a stored procedure to fetch a comment along with it's id. There are multiple comments and I want to display them but I am having problem with display all the records. Here is my code:

Using con
Using sda As New SqlDataAdapter()
Try
cmd.Connection = con
Catch ex As Exception
Response.Write("Error" & ex.Message)

[code]...

How do I make it so that the returned results will be like this:

                 6 First Comment

                 7 Second Comment

View 1 Replies

Web Forms :: Adding Rows To Datatable

Dec 6, 2011

I have added a row to a datatable and displayed this datatable by binding it to gridview.. Later if i add another row to the same table, the data table displays only the recently added row.. I need to display the previously added row along with the newly added row.. How to do this?

View 1 Replies

Web Forms :: Copy Rows From DataTable To Another?

Feb 26, 2012

I want to copy rows from one datatable to another.

View 1 Replies

DataSource Controls :: System.Data.Datatable Updating SQL Server Image Field

Jul 1, 2010

I have a datatable for which i'm defining a dataadapter. I'm specifying an updatecommand with sqlparameters for the dataadapter I set the updatecommand's parameters using the following overload:

[Code]....

The length 16 is used because this is the length of the field according to sql (the image datafield is a pointer of size 16) I noticed .Net is actually truncating the string because of the length i'm setting. An image of size 3kb will properly upload if we set the length field to be greater than 3kb The question I have is what is the proper value (or strategy) to use in order to set for the length field so that ALL images will properly update to the database, with each using the appropriate size.

I guess i could theoretically set the length to be maxint, but this seems sloppy. Looking at sqlparameter documentation i didnt see an 'unlimited' or 'default' length i could set, which would allow each update statement called to use the appropriate size for the data length for that row.

View 1 Replies

Forms Data Controls :: Updating All Rows In Gridview

Jul 30, 2010

Having a bit of difficulty working this gridview update problem out - I have managed to get edit/update function working but instead of only updating the current gridview row it is updating the whole table I believe this is due to a missing where statement on my Update statement - to single out the row index of my grid row.When I configure my sql datasource I am using custom statements Here is my update statement

UPDATE SimpData SET store_nbr = @store_nbr, date = @date, data_type = @data_type, acct_1 = @acct_1, amt_1 = @amt_1, acct_2 = @acct_2, amt_2 = @amt_2, acct_3 = @acct_3, amt_3 = @amt_3, cheque_nbr = @cheque_nbr, cheque_amt = @cheque_amt, gst_hst = @gst_hst, qst = @qst, comments = @comments, uploaded = @uploaded

Here is my gridview

<asp:GridView
ID="GridView1"
runat="server"
CellPadding="4"
Font-Names="Arial"
ForeColor="#333333"
GridLines="None"
Font-Size="Smaller"
Width="100%"
AllowPaging="True"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnRowCommand="GridView1_RowCommand"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<RowStyle
BackColor="#EFF3FB"
/>
<FooterStyle
BackColor="#507CD1"
Font-Bold="True"
ForeColor="White"
/>
<PagerStyle
BackColor="#2461BF"
ForeColor="White"
HorizontalAlign="Center"
/>
<SelectedRowStyle
BackColor="#D1DDF1"
Font-Bold="True"
ForeColor="#333333"
/>
<HeaderStyle
BackColor="#507CD1"
Font-Bold="True"
ForeColor="White"
Font-Size="Smaller"
/>
<EditRowStyle
BackColor="#2461BF"
/>
<AlternatingRowStyle
BackColor="White"
/>
<Columns>
<asp:ButtonField
ButtonType="Button"
CommandName="Select"
HeaderText="Select item to delete"
ShowHeader="True"
Text="Delete">
<ControlStyle
Font-Size="Smaller"
/>
</asp:ButtonField>
<asp:CommandField
ShowEditButton="True"
/>
<asp:ButtonField
ButtonType="Button"
CommandName="Select"
HeaderText="Select item to upload"
ShowHeader="True"
Text="Upload">
<ControlStyle
Font-Size="Smaller"
/>
</asp:ButtonField>
<asp:BoundField
DataField="store_nbr"
HeaderText="Store Number"
SortExpression="store_nbr"
/>...............

View 2 Replies

Forms Data Controls :: Updating Rows In .NET Using Gridview?

Jun 14, 2010

When i update rows using gridview itz updating as m"System.Web.UI.WebControls.TextBox" what should i do?

View 22 Replies

DataTable.Rows.Find Returns Null

Feb 13, 2010

I have a DataTable for which a PrimaryKey constraint has been set to be a combination of an integer column and a datetime column. When I try to 'Find' a row by saying,

dtFunds.Rows.Find(iContainerIndex)

I get a null value. iContainerIndex has been defined as an object array of size 2 with the integer ID and date values in it.

When I set a breakpoint in my code, I see that the very same values are present in the datatable.

If I try to execute, DataTable.Select() method with the integer column filter, I get a result - but returns no result when called with the date column filter.

What am I doing wrong here? The very same DateTime value is present in the datatable.

View 1 Replies

SQL Server :: Transpose Rows To Columns In Datatable

Feb 23, 2011

This is datat table format :

TagName Timestamp Value
Tag1 21-2-2011 12
Tag1 22-2-2011 1
Tag2 21-2-2011 13

I want in this Format

TimeStamp Tag1 Tag2
21-2-2011 12 13
22-2-2011 1 0

View 6 Replies

DataSource Controls :: How To Add New Rows To Datatable Using Loop

Feb 26, 2010

iam working with gridview in asp.net3.5,Sqlserver2008 I am retrieving data from a SP into a datatable.i need to store this table into gridview. but am getting the last row from my datatable into my gridview.

here i need to add each row to the datatable.

my grid is like this:

[Code]....

View 5 Replies

C# - SqlDataAdapter.Fill(DataTable) Returns No Rows?

Feb 7, 2011

I am trying to use a SqlDataAdapter to fill a DataTable, which I use as a data source to a DataGrid. The query is fine, at least when I run it manually in SSMSE. When I do the fill operation, the table gets the right columns, but no rows. The most frustrating part of this is that the code is identical (with a different query) on a different page. I cannot post the query, but my initialization code looks like this:

SqlCommand areaDAC = new SqlCommand (areaQuery, connection);
areaDAC.Parameters.Add (new SqlParameter ("@param", System.Data.SqlDbType.NVarChar, 50));
m_areaDataAdapter = new SqlDataAdapter (areaDAC);

Then to use it:

m_areaDataAdapter.SelectCommand.Parameters["@param"].Value = "Filter Val";
DataTable table = new DataTable ();
m_areaDataAdapter.Fill (table);

At this point, table has the right number of columns and no rows. I know the parameters are being added correctly, I know that data exists for the given query.

Update (as provided by Nik in a comment):

[Code]....

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved