- Retrieving single value from query
- public int GetUserRole(string CUSER)
- {
- try
- {
- SQLCON = new SqlConnection(connectionString);
- SQLCON.Open();
- SQLCommand = new SqlCommand();
- SQLCommand.CommandType = CommandType.Text;
- SQLCommand.Parameters.Add("USUsername", SqlDbType.VarChar).Value = CUSER;
- SQLCommand.CommandText = "SELECT USRole FROM tblUser WHERE USUsername = CUSER";
- Int32 USRole = (Int32) SQLCommand.ExecuteScalar();
- return USRole;
- }
- catch
- {
- HttpContext.Current.Response.Redirect("~/ErrorRedirect.aspx", false);
- return 0;
- }
- }
- ALTER PROCEDURE [dbo].[spGetUserRole]
- -- Add the parameters for the stored procedure here
- @username VARCHAR(50)
- AS
- BEGIN
- -- Declare the return variable here
- DECLARE @USRole as int
- -- Add the T-SQL statements to compute the return value here
- SELECT @USRole = tblUser.USRole FROM tblUser WHERE USUsername = @username
- -- Return the result of the function
- RETURN @USRole
- END
- public int GetUserRole(string CUSER)
- {
- try
- {
- SQLCON = new SqlConnection(connectionString);
- SQLCON.Open();
- SQLCommand = new SqlCommand();
- SQLCommand.CommandType = CommandType.Text;
- SQLCommand.Parameters.Add("USUsername", SqlDbType.VarChar).Value = CUSER;
- SQLCommand.CommandText = "SELECT USRole FROM tblUser WHERE USUsername = @USUsername";
- Int32 USRole = (Int32) SQLCommand.ExecuteScalar();
- return USRole;
- }
- catch (Exception)
- {
- HttpContext.Current.Response.Redirect("~/ErrorRedirect.aspx", false);
- return 0;
- }
- }
- ALTER PROCEDURE [dbo].[spGetUserRole]
- -- Add the parameters for the stored procedure here
- @USUsername VARCHAR(50)
- AS
- BEGIN
- -- Add the T-SQL statements to compute the return value here
- SELECT tblUser.USRole FROM tblUser WHERE USUsername = @USUsername
- END
- "SELECT USRole FROM tblUser WHERE USUsername = CUSER"
- SQLCommand.Parameters.Add("@USUsername", SqlDbType.VarChar).Value = CUSER;
- "SELECT USRole FROM tblUser WHERE USUsername = @USUsername"
- ALTER PROCEDURE [dbo].[spGetUserRole]
- -- Add the parameters for the stored procedure here
- @USUsername VARCHAR(50)
- AS
- BEGIN
- -- Add the T-SQL statements to compute the return value here
- Select tblUser.USRole
- FROM tblUser
- WHERE USUsername = @USUsername
- END
- public int GetUserRole(string CUSER)
- {
- try
- {
- SQLCON = new SqlConnection(connectionString);
- SQLCON.Open();
- SQLCommand = new SqlCommand();
- SQLCommand.CommandType = CommandType.Text;
- SQLCommand.CommandText = "SELECT USRole FROM tblUser WHERE USUsername = @USUsername ";
- SQLCommand.Parameters.Add("USUsername", SqlDbType.VarChar).Value = CUSER;
- Int32 USRole = (Int32) SQLCommand.ExecuteScalar();
- return USRole;
- }
- catch (Exception)
- {
- HttpContext.Current.Response.Redirect("~/ErrorRedirect.aspx", false);
- return 0;
- }
- finally { close connection here.. }
- }
- SqlParameter p = cmd.Parameters.Add("@USRole", SqlDbType.Int);
- p.Direction = ParameterDirection.ReturnValue;
- cmd.ExecuteNonQuery();
- int returnvalue = (int)cmd.Parameters["@USRole"].Value;