problem with the C# code
I am new to C#. i have written a function (method) in C# to connect with the SQL Database. if the UserID and Designation is true then it has to go for appropriate aspx page in C# but i am not getting how to call that method
i have table Users which consists of UserID(datatype as varchar) ,Password (datatype is varchar) and Role (datatype as varchar)
here is the code
namespace MyKlaus
{
public class AllFunctions
{
public static object DBconnection(string UserID, string Password)
{
try
{
SqlConnection con = new SqlConnection(@"Data Source=localhost\sqlexpress;Initial Catalog=klauDB;Trusted_Connection=true");
SqlCommand cmd = new SqlCommand("SELECT Username,Password from Login where Username='" + UserID + "' and Password='" + Password + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
HttpContext.Current.Response.Redirect("HomePage.aspx");
}
else
{
HttpContext.Current.Response.Write("<script type='text/javascript'>alert('Login Failed!')</script>");
HttpContext.Current.Response.Flush();
}
con.Close();
}
catch
{
return null;
}
}
}