I have the following code behind asp.net c#. It works fine, and now I want to put them into class and save in Bin folder.
Can you show me what I need to edit inside of the following codes, and save in class in bin folder?
and I will have login.aspx and use code behind to call the class back. How can I do that?
I will give out 500 pts for this question
Note: You can ignore the dbReader object, and simply return value (LoginChkCommand.Parameter
s["@retval
"].Value)
protected void cmdlogin_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection();
try
{
//create db connection and open it
string ConnectionString = ConfigurationSettings.AppS
ettings["D
Bconnectio
n"];
string CommandText = "up_IsValidLogon";
myConnection.ConnectionStr
ing = ConnectionString;
SqlCommand LoginChkCommand = new SqlCommand(CommandText, myConnection);
LoginChkCommand.CommandTyp
e = CommandType.StoredProcedur
e;
//need to add parameter
//**********************
SqlParameter var1 = new SqlParameter();
var1.ParameterName = "@username";
var1.SqlDbType = SqlDbType.VarChar;
var1.Value = UserName.Text;
LoginChkCommand.Parameters
.Add(var1)
;
SqlParameter var2 = new SqlParameter();
var2.ParameterName = "@password";
var2.SqlDbType = SqlDbType.VarChar;
var2.Value = UserPass.Text;
LoginChkCommand.Parameters
.Add(var2)
;
SqlParameter var3 = new SqlParameter();
var3.ParameterName = "@retval";
var3.SqlDbType = SqlDbType.Int;
var3.Direction = ParameterDirection.Output;
LoginChkCommand.Parameters
.Add(var3)
;
//**********************
myConnection.Open();
SqlDataReader myReader = LoginChkCommand.ExecuteRea
der();
GridView1.DataSource = myReader;
GridView1.DataBind();
myReader.Close();
//**********************
//now get the output parameter:
lblmsg.Text = LoginChkCommand.Parameters
["@retval"
].Value
//**********************
}
catch (Exception ex)
{
throw (ex);
}
finally
{
myConnection.Close();
}
}
Start Free Trial