Click here to Skip to main content
15,923,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have different text boxes in one page. and i have to fetch total number of items in textboxes.for e.g total no of candidates in one text box from candidtae table and total no of company in other text box from company table.plz help me?
Posted
Updated 17-Jun-12 19:35pm
v3

hello,

so whats the problem,

make a query to fetch total numbers of candidates and company also and place the results in the text boxes.


Regards,

Amol
 
Share this answer
 
use function
SQL
public void GetNoofData(string Query,TextBox tx)
{
//-- excecute your Query and set data in Textbox tx 
}


call like that

C#
GetNoOfData("select count(UrFieldName) from UrTableName",txt);

GetNoOfData("select count(UrFieldName) from UrTableName1",txt1);
 
Share this answer
 
Hi,
The best way to solve your sollution what i can suggest is.

a) write generic function/ method in your DAL to fetch data from tatabase in a dataset. like following

C#
public int GetCount(string tablename, string field)
{
//// tablename = database table name
//// field = field on which count is required
}


or

C#
public dataset GetData(string tablename, string querystring)
{
//// tablename = database table name
//// querystring = query to fetch your desired data in a data set.
}


Now in the UI part
b) if it is count that you want then you can directly fetch from the return of GetCount function.

else you can get a dataset which can be further used to fetch data from to be inserted into the textbox as the following code.

C#
Dataset retDataset = objDAL.GetData("yourTAble", query);
txtDesired.Text = retDataset.Tables["yourTAble"].Rows[0]["field"].ToString();


Hope this will guide you to correct path solving your problem.
Thanks
Amit Dutta
 
Share this answer
 
v2
Comments
Member 9027346 18-Jun-12 2:15am    
bt i want to use different tables in one page for different textboxes.
AmitDutta_Bokaro 18-Jun-12 2:20am    
Yes you can, it all depends on you .
A data set can acomodate multiple table and also you will have to write the desired sql query yourself.
The above code is sufficient to handle your problem.
you can share the sollution with your seniour is you can not understand it then he will modify it only a bit what is required and your problem will be sorted out, HAve a gr8 day.
Sandeep Mewara 18-Jun-12 2:55am    
Always use PRE tags to format your code part. It makes the answer readable.

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