Click to See Complete Forum and Search --> : retrieve a Column in C# from sql


m0j1
July 18th, 2010, 10:44 AM
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?
thanks

m0j1
July 19th, 2010, 05:01 PM
thanks you all guys ;)