Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi All,
I am working on a project that involves presenting results of count and sum calculations from an sql database to a label box in c sharp.

I need help on how to link the results i get on sql to reflect on my c# software.

This is exactly what i wanna do....
I wana put the result of "SELECT COUNT (*) FROM singleinput" from an sql database into a label in C#
is that possible in C#

Please help me.

Thanks in Advance.
Posted
Updated 21-Jun-11 10:22am
v3
Comments
RakeshMeena 21-Jun-11 0:18am    
Post if you have tried something, we'll be able to help you better that way.
parmar_punit 22-Jun-11 1:26am    
see my solution no.10
it is what you want exactly.

Have a look at this article below to get an idea on how to acess sql server in C#

Beginners guide to accessing SQL Server through C#[^]
 
Share this answer
 
Comments
[no name] 21-Jun-11 9:28am    
good link
thanks Ramalinga Koushik for modifying the question.
 
Share this answer
 
Comments
[no name] 21-Jun-11 9:31am    
Please try to use comments to share feedback :)
hi guys....
this is exactly what i wanna do....
i wana put the result of "SELECT COUNT (*) FROM singleinput" into a label
is that possible in c#
 
Share this answer
 
It is possible, you retrieve the value from database and save assign it to label.txt value.
 
Share this answer
 
hi Member 7697262, can u please send me the code on how to do it or may be an sample example on how to do it.
thanks a million
i really appreciate
 
Share this answer
 
You Can Use Assign
label1.text = Com1.Executescalar(Query).ToString();
Plz Check
 
Share this answer
 
C#
SqlCommand cmd = new SqlCommand("SELECT COUNT (*) FROM singleinput", con);
int count = 0;
try
{
    con.Open();
    object total = cmd.ExecuteScalar();
    if (total != null)
    {
        try
        {
            count = Convert.ToInt32(total);
        }
        catch
        {
            count = 0;
        }
    }
}
catch (Exception ex)
{
    MessageBox.Show("error : " + ex.Message);
}
finally
{
    con.Close();
}
label1.Text = count.ToString();
 
Share this answer
 
Comments
[no name] 22-Jun-11 1:42am    
hahaha that's good.
xlboyz 22-Jun-11 2:36am    
Thanks A million....
I really really really really appreciate
once again Thankzzzzzz
parmar_punit 22-Jun-11 2:47am    
Thanks for accepting and appreciating the answer.
Thanks alot Guyz, y'all were really helpful.
I tried Member_6499766 solution and it worked perfectly.
i was so excited i almost knocked my TV down....lol
really, u guyz are the best.
i'll be sure to refrence y'all when i'm done with the project.
once again thankz
 
Share this answer
 
You need to pick up a book on C# and read it,
 
Share this answer
 
Hope this[^] might help you.
 
Share this answer
 
Comments
[no name] 21-Jun-11 9:29am    
good one

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