.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Checking Existing Records Data Rows

Posted By:Majith       Posted Date: September 08, 2010    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

This code explains the method to check existing records without using any loops and to improve the code performance.

Checking Existing Records Using Array of Data Rows:


This code explains the method to check the existing database records without using for loops and improving the performance to the applications.

Whenever we need to identify the duplicate records, normally we count the total number of records from dataset or any database objects and using for loop we will check routine to the records.

For Example : 

if your table having thousand records then you are doing search operation in the data table using for loops. 

This code can be used in all pages whenever we checking the existing records.

Problem Identification:

1.      Unnecessary to wallop the database

 2.      using for loops for each and every record checking

DataSet dsNew = GetDataSet();
for (int lvar = 0; lvar < dsNew.Tables[0].Rows.Count; lvar ++) {
   if (txt_Name.Text.ToString().Trim() ==  dsNew.Tables[0].Rows[lvar]["Name"].ToString().Trim())
     Label_Error.Text = "Record Already Exists";

Problem Solution:

  1. Avoiding the for loop 
  2. Restricting round trip process of Database


DataSet dsCheck = GetDataSet();
DataRow[] drName = dsCheck.Tables[0].Select("Name='" + txt_Name.Text.ToString().Trim() + "'");
if (drName.Length > 0)
Label_Error.Text = " Record Already Exists"; 
Happy Coding!
 Subscribe to Articles


Further Readings:

Author: newery         Company URL: http://www.dotnetspark.com
Posted Date: September 11, 2010

use linq

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend