Click here to Skip to main content
15,887,966 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with SQL Update using Variables in C# Pin
PIEBALDconsult17-Sep-07 18:34
mvePIEBALDconsult17-Sep-07 18:34 
AnswerRe: Problem with SQL Update using Variables in C# Pin
ba1959nh18-Sep-07 2:58
ba1959nh18-Sep-07 2:58 
GeneralRe: Problem with SQL Update using Variables in C# Pin
PIEBALDconsult18-Sep-07 5:03
mvePIEBALDconsult18-Sep-07 5:03 
QuestionQuestion on checkedlistbox if statement Pin
falles0117-Sep-07 15:27
falles0117-Sep-07 15:27 
QuestionLogon with UserName and Password Pin
T4AMD17-Sep-07 12:15
T4AMD17-Sep-07 12:15 
AnswerRe: Logon with UserName and Password Pin
ChrisKo17-Sep-07 12:33
ChrisKo17-Sep-07 12:33 
QuestionRe: Logon with UserName and Password Pin
T4AMD17-Sep-07 12:42
T4AMD17-Sep-07 12:42 
AnswerRe: Logon with UserName and Password Pin
ChrisKo17-Sep-07 12:50
ChrisKo17-Sep-07 12:50 
SqlConnection sqlconSource = new SqlConnection(ConfigurationManager.AppSettings["cs"]);
SqlCommand sqlcmdSource = new SqlCommand("LogOn", sqlconSource);
sqlcmdSource.CommandType = CommandType.StoredProcedure;
sqlcmdSource.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar, 40));
sqlcmdSource.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 10));
sqlcmdSource.Parameters["@UserName"].Value = txtUserName.Text;
sqlcmdSource.Parameters["@Password"].Value = txtPassword.Text;

sqlconSource.Open();

if (sqlcmdSource.ExecuteScalar().ToString() == "0")
   Response.Redirect("AccessDenied.aspx");
else
   Response.Redirect("FileManager.aspx");

sqlconSource.Close();


If you want the Try{} Catch{} because you want to handle a specific SQL exception then do it this way

Try
{
   SqlConnection sqlconSource = new SqlConnection(ConfigurationManager.AppSettings["cs"]);
   SqlCommand sqlcmdSource = new SqlCommand("LogOn", sqlconSource);
   sqlcmdSource.CommandType = CommandType.StoredProcedure;
   sqlcmdSource.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar, 40));
   sqlcmdSource.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 10));
   sqlcmdSource.Parameters["@UserName"].Value = txtUserName.Text;
   sqlcmdSource.Parameters["@Password"].Value = txtPassword.Text;

   sqlconSource.Open();

   if (sqlcmdSource.ExecuteScalar().ToString() == "0")
      Response.Redirect("AccessDenied.aspx");
   else
      Response.Redirect("FileManager.aspx");
}


Catch (SqlException e)
{
//however you want to handle the exception
}


Finally
{
   if (sqlconSource.State == ConnectionState.Open)
      sqlconSource.Close();
}

AnswerRe: Logon with UserName and Password Pin
PIEBALDconsult17-Sep-07 14:01
mvePIEBALDconsult17-Sep-07 14:01 
QuestionConsole application keypress Pin
ballzinator17-Sep-07 11:50
ballzinator17-Sep-07 11:50 
AnswerRe: Console application keypress Pin
ChrisKo17-Sep-07 12:27
ChrisKo17-Sep-07 12:27 
GeneralRe: Console application keypress Pin
ballzinator18-Sep-07 3:27
ballzinator18-Sep-07 3:27 
GeneralRe: Console application keypress Pin
Big Daddy Farang18-Sep-07 8:22
Big Daddy Farang18-Sep-07 8:22 
Questionwhat is better c# or vb.net ?? Pin
sofy200817-Sep-07 11:49
sofy200817-Sep-07 11:49 
AnswerRe: what is better c# or vb.net ?? Pin
Matthew Cuba17-Sep-07 12:42
Matthew Cuba17-Sep-07 12:42 
AnswerRe: what is better c# or vb.net ?? Pin
Patrick Etc.17-Sep-07 13:33
Patrick Etc.17-Sep-07 13:33 
GeneralRe: what is better c# or vb.net ?? Pin
PIEBALDconsult17-Sep-07 13:58
mvePIEBALDconsult17-Sep-07 13:58 
GeneralRe: what is better c# or vb.net ?? Pin
Luc Pattyn17-Sep-07 14:41
sitebuilderLuc Pattyn17-Sep-07 14:41 
AnswerRe: what is better c# or vb.net ?? Pin
BoneSoft17-Sep-07 17:50
BoneSoft17-Sep-07 17:50 
GeneralRe: what is better c# or vb.net ?? Pin
Big Daddy Farang18-Sep-07 8:30
Big Daddy Farang18-Sep-07 8:30 
GeneralRe: what is better c# or vb.net ?? Pin
BoneSoft18-Sep-07 8:51
BoneSoft18-Sep-07 8:51 
AnswerRe: what is better c# or vb.net ?? Pin
PIEBALDconsult17-Sep-07 18:15
mvePIEBALDconsult17-Sep-07 18:15 
AnswerRe: what is better c# or vb.net ?? Pin
Nouman Bhatti17-Sep-07 18:58
Nouman Bhatti17-Sep-07 18:58 
GeneralRe: what is better c# or vb.net ?? Pin
sofy200818-Sep-07 9:18
sofy200818-Sep-07 9:18 
QuestionHow to connect to network printer via C# Pin
coleschuk17-Sep-07 11:07
coleschuk17-Sep-07 11:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.