473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to fetch all rows inserted in datagirdview in c#

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 1418
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 Expert Mod 8TB
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.