Last post Dec 30, 2012 07:59 PM by Decker Dong - MSFT
Dec 30, 2012 07:30 AM|hkbeer|LINK
I have a AccessDataSource control which successfully get the data from TableA of field ProductID, ProductName.
Now I need to get Select ProductName where ProductID =1 so I type this into SelectCommand and it can display the record into Gridview, meaning the AccessDataSource is perfect.
However, instead of Gridview, I need to get that ProductName into label1.text.
What should be the easiest way and code for so doing ?
Dec 30, 2012 07:48 AM|oned_gk|LINK
DataTable dt = ((DataView)AccessDataSource1.Select(DataSourceSelectArguments.Empty)).Table;
Label1.Text = dt.Rows.ToString();
Dec 30, 2012 07:59 PM|Decker Dong - MSFT|LINK
Any data source is used to bind data contents directly to the data presentation control, so you don't need to use this if you only wanna fetch a single value. Please use SqlCommand instead:
private static void ReadOrderData(string connectionString)
string commandText = "SELECT TOP1 FieldName FROM xxx;";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(commandText, connection))
using (SqlDataReader reader = command.ExecuteReader())
Label1.Text = reader.GetString(fieldindex,0-based);