Jump to content

How to get a value from a sql server database and display it in a label using c#?

i want to get a value from a column in my sql server database and display it in a label. so far i tried this but it didnt work.any suggestions how to get this working?

   SqlDataReader myReader = null;
    SqlCommand    myCommand = new SqlCommand("select details from Pictures where id ='"+x+"'");
    myReader = myCommand.ExecuteReader();
    label1.Text = myCommand.ToString();

 

Link to comment
Share on other sites

Link to post
Share on other sites

You should really be using DataSets and TableAdapters if you're doing much meaningful database interaction.  They provide a strongly typed and locally cached abstraction over your actual database interface.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×