我想從我的數據庫中選擇一些字段並將它們存儲爲變量,以便我可以使用它們在我的頁面上顯示數據。到目前爲止,我有這樣的:將SQL字段存儲爲變量?
protected void DefaultGrid_SelectedIndexChanged(Object sender, EventArgs e)
{
string firstName;
GridViewRow row = DefaultGrid.SelectedRow;
int id = Convert.ToInt32(row.Cells[9].Text);
string checkStatement = "Return fName FROM SecureOrders WHERE IdentityColumn LIKE @identity";
using (SqlConnection connection = new SqlConnection(connectionString.ToString()))
using (SqlCommand _check = new SqlCommand(checkStatement, connection))
{
_check.Parameters.Add("@identity", SqlDbType.Int).Value = id;
connection.Open();
_check.ExecuteNonQuery();
connection.Close();
}
我不知道我應該如何改變,這樣我可以救場FNAME在叫的firstName變量。我在正確的軌道上嗎?
我想你的意思是'SELECT fName ...' – SLaks