problem with the C# code
Hello,
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("");
HttpContext.Current.Response.Flush();
}
con.Close();
}
catch
{
return null;
}
}
}
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("");
HttpContext.Current.Response.Flush();
}
con.Close();
}
catch
{
return null;
}
}
}
Replies
-
Neeraj SharmaCan you please post in your code so that we can have a look at the issue more clearly
-
simplycodertry using Convert.ToBoolean(...)
this is a wild guess from your question,
if this doesnt work, kindly post the code which you think causes the problem. -
YashuAsha
thank you, I have made mistake in giving the parameters this error (cannot implicitly convert int into bool) is solved.Nick_SharmaCan you please post in your code so that we can have a look at the issue more clearly
i have posted the code. i am not getting how to call DBconnection function. Can anyone help me -
YashuAshaAlso i am getting error as DBconnection(string, string) not all code paths returns a value
-
simplycoderYou are missing some return statement.
Please Post the relevant code.
You are reading an archived discussion.
Related Posts
I want to do a research on the above named topic, and I was hoping I could get the views of colleague Engineers
could anyone please guide me how to publish a research paper in my field i.e Computer Science and Engineering????
I want to place an event in college tech fest in electronics department. So i want ideas of different events which can be placed in the tech fest.
before a week i got the fake emails from Reserve bank of India,Maruti suzuki,coco-cola....i know it's fake but i don't know how to stop that fake email...if any one teach...
Hai my name shivaraj v arali.. studying computer science engg in bec bagalkot..