serving the solutions day and night

Pages

Sunday, April 4, 2010

C# Code

C# Functions
<%@ Page CodeBehind="about_us.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="localhost.about_us" %>

#region "Member Variables"
private int intUserID;
private string strSalutation;
private string strFName;
#endregion "Member Variables"

Session
1) if (Session["PTLUserID"] != "0" & Session["PTLUserID"] != null)
2) Session["PTLLinkFile"]="Documents/Process-TrakWebinar.pdf";

Response, Request and Server
1) Response.Redirect("Documents/Process-TrakWebinar.pdf");
2) Server.Transfer("login.aspx");

Mail
1) using System.Web.Mail;
2) msgMail.To = toAdd;
3) msgMail.From = toAdd;
4) msgMail.Subject = subjectc;
5) msgMail.BodyFormat = MailFormat.Html;
6) msgMail.Body = bodyc;
7) SmtpMail.SmtpServer = strMailServer;
8) SmtpMail.Send(msgMail);

SQL SERVER
1) using System.Data;
using System.Data.SqlClient;
2) private SqlCommand cmd = new SqlCommand();
3) private SqlConnection conn = new SqlConnection();
4) SqlParameter iOutput = new SqlParameter("@newIndex", SqlDbType.Int);
5) try
{
conn = new SqlConnection(strConnection);
conn.Open();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@username", UserName);
cmd.Parameters.Add("@password", Password);
iOutput.Direction = ParameterDirection.Output;
cmd.Parameters.Add(iOutput);
cmd.CommandText = "spUserLogin";
cmd.ExecuteNonQuery();
UserID = (int)iOutput.Value;
cmd.Dispose();
}
catch (Exception excep)
{
throw new Exception(excep.Message);
}
finally
{
conn.Close();
}

Web Configuration
1) using System;
using System.Configuration;
2) private string strConnection = ConfigurationSettings.AppSettings.Get("ConnectionString");

Data Types & Declaraion, Properties, Function, null, condtions
1) public class User
2) private int intUserID;
3) private Boolean blnActive;
4) string strLinkFile;
5)public int UserID
{
get
{
return intUserID;
}
set
{
intUserID = value;
}
}
6) calling function
User user = new User();
user.Active=false;
7) if (user.UserID != 0)
8) if (strLinkFile != null)
9) if (strLinkFile.Length>0)
10) if (Session["PTLUserID"] != "0" & Session["PTLUserID"] != null)
11) if (IsPostBack) {} else { }
12) if (strName=="" || strEmail=="" || strPhone=="")

Tips SQL SERVER
BULK INSERT dbo.[tablename] FROM 'c:\temp\bulkinsertfile.csv' WITH (FIELDTERMINATOR=';',ROWTERMINATOR='\n',CODEPAGE = 'ACP',FIRSTROW=2)

No comments: