This code explains the method to check the existing database records without using for loops and improving the performance to the applications.
Checking Existing Records Using Array of Data Rows:
Introduction:
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.
In case if your table having one thousand records means then the calculative time will go higher and it slow down the process.
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”;
return;
}
}
Problem Solution:
- Avoiding the for loop
- 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";
return;
}
Conclusion:
Here we don’t used for loop and no hitting the databases, just checking the datarow length with minimal code.
Cheers,,