Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I am entering account number in text box.

so i want to check of the account number is present in table then it will fetch all the records of that number else it will give error.

please tell how to do that..
Posted

SQL
SELECT COUNT(*) FROM MyTable WHERE AccountNumber=1234
Will return the number of matching records.
SQL
SELECT * FROM MyTable WHERE AccountNumber=1234
Will return all matching records.

You can just use the latter one and check if any records are returned - but exactly how in your C# code depends on how it currently works - and we can't see that.
But this might help: Using PostgreSQL in your C# (.NET) application (An introduction)[^]
 
Share this answer
 
try this using LinQ to Sql approach

C#
var container=NameOfYourEntity.YourTable.Where(x=>x.AccountNumber==Int.Parse(TextBox.Text)).FirstOrDefault();

if(container!=null)
{
 //get the data from container variable
}
else
{
 //do something if no record found
}
//NameOfYourEntity is the instance of your edmx file using Entity Framework

you can also read this for another sample of LinQ To SQL

hope it will help. . :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900