473,654 Members | 3,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i set DataRow class to last row of a Sql table

44 New Member
I have to add a value to an empty field in the last row of the table using C#.

What changes should i make to the following code so that i can set 'thisRow' to last row in the table rather than to a new row.

DataRow thisRow = thisDataSet.Tab les["Table"].NewRow();
thisRow["Exit_time"] = Exittime;
thisDataSet.Tab les["Table"].Rows.Add(thisR ow);
Oct 29 '07 #1
27 1710
Plater
7,872 Recognized Expert Expert
Rows contain data. If they don't, they aren't real.
A "blank row" at the end of the table is just a template for filling in a new row.

Unluess you allow nulls in every column and create a row with nothing but nulls in it and don't have any auto-incrementing fields and no primary key.
Oct 29 '07 #2
pugalenthi
44 New Member
Rows contain data. If they don't, they aren't real.
A "blank row" at the end of the table is just a template for filling in a new row.

Unluess you allow nulls in every column and create a row with nothing but nulls in it and don't have any auto-incrementing fields and no primary key.
I guess you misunderstood what i said. In my table the last row has data in every column except for 1 column, which allows null. And now i need to insert value into this column in the last row. The value of this column will be a output of the c# program.
Oct 29 '07 #3
Plater
7,872 Recognized Expert Expert
Scracth that.
You want to enter the data into the last row of a datatable in code?

You should be able to do this?
Expand|Select|Wrap|Line Numbers
  1. int lastrowidx=thisDataSet.Tables["Table"].Rows.Count-1;
  2. DataRow thisRow = thisDataSet.Tables["Table"].Rows[lastrowidx];
  3. thisRow["Exit_time"] = Exittime;
  4.  
Oct 29 '07 #4
pugalenthi
44 New Member
Scracth that.
You want to enter the data into the last row of a datatable in code?

You should be able to do this?
Expand|Select|Wrap|Line Numbers
  1. int lastrowidx=thisDataSet.Tables["Table"].Rows.Count-1;
  2. DataRow thisRow = thisDataSet.Tables["Table"].Rows[lastrowidx];
  3. thisRow["Exit_time"] = Exittime;
  4.  
I tried the above code in my program, and finally used the following lines,

thisDataSet.Tab les["Table"].Rows.Add(thisR ow);
thisAdapter.Upd ate(thisDataSet , "Table");

while i executed the code i got two exception,

System.Argument Exception occured in System.Data.dll
System.Reflecti on.TargetInvoca tionException occured in mscorlib.dll

I was not able to update the column of last row with the output of my program.
Oct 30 '07 #5
Plater
7,872 Recognized Expert Expert
Oh, I thought the Row was already IN the DataTable.

What part is triggering the argument exception?
Oct 30 '07 #6
pugalenthi
44 New Member
Oh, I thought the Row was already IN the DataTable.

What part is triggering the argument exception?
int lastrowidx=this DataSet.Tables["Table"].Rows.Count-1;
DataRow thisRow = thisDataSet.Tab les["Table"].Rows[lastrowidx];
thisRow["Exit_time"] = Exittime;
thisDataSet.Tab les["Table"].Rows.Add(thisR ow);
thisAdapter.Upd ate(thisDataSet , "Table");

The first 3 lines of the code working perfectly fine. The variable Exittime's value gets passed to thisRow["Exit_time"]. I guess the problem is in the last two lines.

I need to just insert value into one column of the last row, whose other columns are already filled.
Oct 30 '07 #7
Plater
7,872 Recognized Expert Expert
Is there a column with that name in the datatable?
Oct 30 '07 #8
pugalenthi
44 New Member
Is there a column with that name in the datatable?
Yes there is a column named Exit_time.
Oct 30 '07 #9
Plater
7,872 Recognized Expert Expert
I take it that it's sqldatatype is that of "datetime" is the "exittime" variable you're trying to set it also a datetime object?


And to make sure we're on the same page:
int lastrowidx=this DataSet.Tables["Table"].Rows.Count-1;
DataRow thisRow = thisDataSet.Tab les["Table"].Rows[lastrowidx];
If you've done the above, I believe this line here will error:
thisDataSet.Tab les["Table"].Rows.Add(thisR ow);


You are in fact using the code you created and not mine (like above)?
Oct 30 '07 #10

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

Similar topics

0
2526
by: dudi | last post by:
I am encountering the following strange problem which causes the application to use more memory then it should. I have 5 database tables. lets pretend I want to load each one of them into a dataTable. then, run over all the rows of the dataTable and for each cell in the dataRow concatenate a string (the value in the cell is a string to begin with). I expect the memory to go up every time I load a dataTable, even go up when I modify the...
1
1385
by: Supa Hoopsa | last post by:
I am sure this must be REALLY simple, but I've spent the last 2 hours trying to failing to figure out how to copy a datarow from an existing table to a new table WITHOUT getting the following error: Run-time exception thrown : System.ArgumentException - This row already belongs to another table. I know the row I want to copy and so my code looks like this: Dim myTable As New DataTable
1
1869
by: Marcel Sottnik | last post by:
Hello group Maybe this is not the right NG, but this problem seems to me to be more language related than ADO.NET. How can I write the constructor for specialization of DataRow which will take a datarow as parameter. Something like: class MyDataRow : DataRow {
2
2496
by: VMI | last post by:
Assuming I have a datarow (or a datarow collection), would it possible to create an Access table and dump the datarow(s) into that Access table? I wouldn't even need to create the fields in the Access table since the datarow contains the exact table schema. I'm currently taking each datarow and creating an Insert statement that i then run against Access.
6
6212
by: André Fereau | last post by:
Hi, I wish to use a class derivated from DataRow. The rows within a table are created with the NewRow method of the DataTable class. So I writed a method NewSTMTTRNRow() in my class STMTTRNDataTable, but I have an Invalid Cast Exception in the code "return ((STMTTRNRow)(this.NewRow()));". Where is the bug? What is the smart way to achieve my goal? Code :
4
2892
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data from the database. However, the two classes don't appear to have any common interfaces that would allow me to enumerate the fields. Yet, when you databind you can pass either of these classes (as well as many others) and .NET somehow knows how...
1
2423
by: Ryan Liu | last post by:
Hi, Is that safe to say a Detached DataRow neve in a DataTable's Rows collectoin? But in my log file, I do see a Detached row: foreach(DataRow dr in this.currentQuotaUserDt.Rows) {
1
2802
by: Arpan | last post by:
This is how I am dynamically adding a table to a DataSet: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'Create an empty DataSet Dim dSet As New DataSet 'Create a new table & add columns Dim dTable As New DataTable("Users") dTable.Columns.Add("ID", Type.GetType("System.Int32"))
2
4827
by: =?Utf-8?B?TWFyYw==?= | last post by:
In Visual Studio 2005, I am developing a Windows Mobile application, using Mobile SQL 2005. I need Data from a Database to be shown in a DataGrid, this works. But now I want to be able to get the Data of the selected DataRow, for instance, I want to display the value of the "Klant" column of the selected Row using: DataRow currentRow = table.Rows; MessageBox.Show(currentRow.ToString());
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
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
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7304
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...
0
5621
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
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.