473,473 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to fetch all rows inserted in datagirdview in c#

3 New Member
I fetch maxid row to view in datagridview using the following code
Expand|Select|Wrap|Line Numbers
  1.  public static DataTable GetMaximpID()
  2.         {
  3.             string strconn = AlShehabi.Properties.Settings.Default.NewSalariesDBConnectionString;
  4.             SqlConnection conn = new SqlConnection(strconn);
  5.  
  6.             if (conn.State == ConnectionState.Closed)
  7.             {
  8.                 conn.Open();
  9.             }
  10.             SqlCommand command = new SqlCommand("select * from Imprests where Imprest_ID= (Select MAX(imprest_ID) FROM Imprests)", conn);
  11.  
  12.             SqlDataAdapter adpater = new SqlDataAdapter(command);
  13.             DataTable dt = new DataTable();
  14.             try
  15.             {
  16.                 adpater.Fill(dt);
  17.             }
  18.  
  19.  
  20.             catch (Exception ex)
  21.             {
  22.                 MessageBox.Show(ex.Message);
  23.             }
  24.  
  25.             conn.Close();
  26.             return dt;
  27.         }
but I want to fetch all rows inserted and view in datagridview
for example if user insert 4 rows I want to view them in datagridview after insert them
using insertbutton_click
Sep 14 '14 #1
2 1421
Gobindap
25 New Member
Database itself does not identify which is new or which is old. We need to shape data table in database in such a way which help to reach our motto. For this create one new column named 'status' as integer in the table where you insert data. Now shape you code to return zero if those records are views else 1. Now when user click on the button select all rows where status row value = 1 i.e. "Select * from dataTable where status=1"

I hope your problem is solved.
Sep 16 '14 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Use the DataTable.GetChanges Method to get the changes made to the DataTable.

If there were changes this will return you a DataTable and you can check the RowState of the Rows in that table for Added rows.


OR you could add a listener for the DataTable RowChanged Event and keep a running list of items that were added.

Or you could add an unnecessary column to keep track of the state as suggested.


There are a lot of ways to accomplish this.




-Frinny
Sep 16 '14 #3

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

Similar topics

3
by: hshen | last post by:
Hi All, I have encountered a weird behavoir of embedded MySQL. Through a simple program I made (in Delphi 6), I can insert rows to a table through embedded MySQL and I can retrieve the rows from...
2
by: Michel Esber | last post by:
System scenario: Linux DB2 Workgroup Server V7 FixPack 13. I have a java application (JDBC v2 driver) that reads into memory a considerable amount of data (100k-300k rows), summarizes the...
0
by: baaul | last post by:
I need to INSERT rows from #temp table into #final table with grp_code and bap_id combination. Thanks. Create Table #tmp ( sort_id int default 0, grp_Code int default 1,...
1
by: juancho8529 | last post by:
I ned know how set the number of rows obtained from a interbase 2.0 query, hi have tried with instructions has fetch rows, limit, top... but i didn't have found a correct result, Please if...
1
by: ozzii | last post by:
Is there any way to retrieve the ids of all rows inserted after importing bulk data using the load infile technique? I need the ids of all rows that have been inserted so that they can be inserted...
2
by: dev177 | last post by:
Hi, I'm pretty new to this community and here's my query. Lets suppose I have executed a DML query on a table (inserted a single row). The table is not having any identity, date or time...
3
by: nrain | last post by:
Hi This is nrain here in a pl/sql block, some rows are getting inserted into the table violating the primary key and going to exception. I need to fetch records and want to check what...
1
by: rajeev patel | last post by:
How to fetch rows into column in gridview with the help of sql server. Id Date Attendance LAB01 2012-06-01 P FBD/SL/01/2012 2012-06-01 A FBD/SL/05/2012 ...
4
by: dazase1 | last post by:
Hi, I have a SQL Database and I wish to obtain records until the customer's quantity requested has been met. Here is what I mean. Request Table Product Quantity Price...
1
by: oconrl4 | last post by:
I need to know how to expand the number of rows to import into an access database from a report. The limit is currently set to 100 rows. The access database is 2003. I am new to access. The users...
0
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,...
0
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,...
0
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.