Hi, a few days i am trying to get one value from one column from database and put in one local variable (INT)......
i trying this:
protectedvoid SqlDataSource1_Load(object sender,EventArgs e)protectedvoid SqlDataSource1_Load(object sender,EventArgs e){
Int32 status;
SqlDataSource1.SelectCommand="SELECT status FROM users WHERE Username='" +Membership.GetUser() +"'";status = SqlDataSource1.Select(DataSourceSelectArguments.Empty);
}
"status" is the variable in question...
anyone can help me?
tank-you.
Prefered way would be ExcuteScalar
protected void ExecuteScalarDemo ( ) {
// specify the data source
SqlConnection myConn = new SqlConnection (
"server=( local )\\NetSDK; trusted_connection=yes; database=pubs" );// define the command query
string query = "SELECT status FROM usersWHERE Username='" +Membership.GetUser() +"'";// initialize command object with the specified query and connection
SqlCommand myCommand = new SqlCommand ( query, myConn );// open the data connection
myConn.Open ( );// execute the command
intstatus = ( int ) myCommand.ExecuteScalar ( );// close the data connection
myConn.Close ( );
}
No comments:
Post a Comment