1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Retrieve Column in C# from SQL

Discussion in 'C#' started by m0j1, Jul 18, 2010.

  1. m0j1

    m0j1 New Member

    Jul 18, 2010
    Likes Received:
    Trophy Points:
    hi , I have a form name "Sale" and it has a comboBox wich shows the products . products list is in a table in sql names Products . the Products table has three columns : ProductName , count , Price .
    I want to retrieve the Price in C# when I click a certain button . I have wrote the code as below but I don't have any idea how to complete it .

    SqlDataAdapter objAdapter = new SqlDataAdapter();
    objAdapter.SelectCommand = new SqlCommand();
    objAdapter.SelectCommand.Connection = objconnection;
    objAdapter.SelectCommand.CommandText = "select Price from Products where ProductName=@ProductName";
    objAdapter.SelectCommand.Parameters.AddWithValue("@ProductName", cmbBox1.Text);

    anyone knows how should I do that?

Share This Page