Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am trying to give out my data in a lable but i have no clue how to do this. I am sure it isnt very difficult...

connectinString = "Data Source = " + fileName + ";max database size=256";
           conn = new SqlCeConnection(connectinString);
           cmd = new SqlCeCommand("SELECT COUNT(*) FROM Pigeons", conn);
           conn.Open();
           <code>MessageBox.Show</code>(cmd.ExecuteScalar().ToString());
           conn.Close();


Now it is shown in a Message Box, but how can i put it into a lable?

private void label1_Click(object sender, EventArgs e)
        {
            
        }


What I have tried:

I looked for solution in the internet, but i couldn't find anything...
Posted
Updated 22-Jul-18 23:23pm

Try this:
C#
connectinString = "Data Source = " + fileName + ";max database size=256";
using (conn = new SqlCeConnection(connectinString))
    {
    using (md = new SqlCeCommand("SELECT COUNT(*) FROM Pigeons", conn))
        {
        conn.Open();
        label1.Text = cmd.ExecuteScalar().ToString();
        }
    }
 
Share this answer
 
label1.Text = cmd.ExecuteScalar().ToString();
 
Share this answer
 
v2

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