18.188.10.246
|
9
FORMATTING DATE
DateTime myDateTime = DateTime.Now; myDateTime.ToString() = 12/01/2004 10:02:10 PM myDateTime.ToString("d") = 12/01/2004 myDateTime.ToString("D") = January 12, 2004 myDateTime.ToString("f") = January 12, 2004 10:02 PM myDateTime.ToString("F") = January 12, 2004 10:02:10 PM myDateTime.ToString("g") = 12/01/2004 10:02 PM myDateTime.ToString("G") = 12/01/2004 10:02:10 PM myDateTime.ToString("m") = January 12 myDateTime.ToString("r") = Mon, 12 Jan 2004 22:02:10 GMT myDateTime.ToString("s") = 2004-01-12T22:02:10 myDateTime.ToString("t") = 10:02 PM myDateTime.ToString("T") = 10:02:10 PM myDateTime.ToString("u") = 2004-01-12 22:02:10Z myDateTime.ToString("U") = January 13, 2004 6:02:10 AM myDateTime.ToString("y") = January, 2004
OLEDB SELECT,INSERT,UPDATE
Make DB Connection
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*FilePath*"); OleDbCommand cmd = new OleDbCommand(); conn.Open();
DataReader
SQL = @"SELECT *FieldName* FROM [*TableName*] WHERE *FieldName* = " + *FieldValue*; cmd = new OleDbCommand(SQL, conn); OleDbDataReader MyReader; MyReader = cmd.ExecuteReader(); if (MyReader.HasRows) { while (MyReader.Read()) { *FieldValue* = MyReader.GetInt32(0); } } else { Response.Write("No rows found."); } MyReader.Close();
Update
SQL = @"UPDATE [*TableName*] SET *FieldName* = '" + *FieldValue* + "', *DateField* = '" + DateTime.Now.ToString() + "' WHERE *FieldID* = " + *FieldValue*; cmd = new OleDbCommand(SQL, conn); cmd.ExecuteNonQuery();
Insert & get autonumber
SQL = @"INSERT INTO [*TableName*] (*FieldNames*) VALUES ('" + FieldValues + "')"; cmd = new OleDbCommand(SQL, conn); cmd.ExecuteNonQuery(); // Get the AutoNumber field value SQL = @"SELECT @@IDENTITY"; cmd = new OleDbCommand(SQL, conn); object *IdentityID* = cmd.ExecuteScalar();
COOKIES
Set cookie
HttpCookie *cookie* = new HttpCookie("*key*"); *cookie*.Value = (string)Session["*key*"]; *cookie*.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(*cookie*);
Get cookie
HttpCookie *cookie* = new HttpCookie("*key*"); *cookie* = Request.Cookies.Get("*key*"); if (*cookie* != null) { *key* = *cookie*.ToString(); }
FILE SYSTEM READER/WRITER
Read file
System.IO.StreamReader reader = new System.IO.StreamReader(System.IO.File.Open(@"*FilePath*", System.IO.FileMode.Open)); String readerInput = reader.ReadToEnd(); reader.Close();
Write file
System.IO.StreamWriter writer = new System.IO.StreamWriter(System.IO.File.Open(@"*FilePath*", System.IO.FileMode.Open)); writer.Write("text output"); writer.Close();
SMTP
MailMessage message = new MailMessage( "*emailAddress*", "*emailAddress*", "Contact from Your Website", *emailMsg*); message.IsBodyHtml = true; SmtpClient client = new SmtpClient("localhost"); try { client.Send(message); } catch (Exception ex) { }
VARIABLE TYPE VALIDATION
Verifying Type Int/Double
double Num; bool isNum = double.TryParse(*stringToValidate*, out Num); if (isNum) { // *stringToValidate* is numeric } |