CodeKeep C# Feed Settembre 30th, 2008
Description: Use to deep clone an object
Link: http://www.codekeep.net/snippets/bef5e8e3-afab-4a9f-ab8f-80084ff5a672.aspx
public class MyObject : ICloneable {
public object Clone()
{
return ObjectUtility.CloneObject(this);
}
}
public static class ObjectUtility {
public static object CloneObject(object obj)
{
using (MemoryStream memStream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter(null,
new StreamingContext(StreamingContextStates.Clone));
binaryFormatter.Serialize(memStream, obj);
memStream.Seek(0, SeekOrigin.Begin);
return binaryFormatter.Deserialize(memStream);
}
}
}

CodeKeep C# Feed Settembre 30th, 2008
->
Description: SqlCommandBuilder object to automatically generate the DeleteCommand, the InsertCommand, and the UpdateCommand properties of the SqlCommand object for a SqlDataAdapter object,
Link: http://www.codekeep.net/snippets/9a6c1dd3-76d0-4490-8fb4-3b8d149d91aa.aspx
using System.Data;
using System.Data.SqlClient;
using System;
namespace Q308507 {
class Class1 {
static void Main(string[] args) {
SqlConnection cn = new SqlConnection();
DataSet CustomersDataSet = new DataSet();
SqlDataAdapter da;
SqlCommandBuilder cmdBuilder;
//Set the connection string of the SqlConnection object to connect
//to the SQL Server database in which you created the sample
//table.
cn.ConnectionString = "Server=server;Database=northwind;UID=login;PWD=password;";
cn.Open();
//Initialize the SqlDataAdapter object by specifying a Select command
//that retrieves data from the sample table.
da = new SqlDataAdapter("select * from CustTest order by CustId", cn);
//Initialize the SqlCommandBuilder object to automatically generate and initialize
//the UpdateCommand, InsertCommand, and DeleteCommand properties of the SqlDataAdapter.
cmdBuilder = new SqlCommandBuilder(da);
//Populate the DataSet by running the Fill method of the SqlDataAdapter.
da.Fill(CustomersDataSet, "Customers");
//Display the Update, Insert, and Delete commands that were automatically generated
//by the SqlCommandBuilder object.
Console.WriteLine("Update command Generated by the Command Builder : ");
Console.WriteLine("==================================================");
Console.WriteLine(cmdBuilder.GetUpdateCommand().CommandText);
Console.WriteLine(" ");
Console.WriteLine("Insert command Generated by the Command Builder : ");
Console.WriteLine("==================================================");
Console.WriteLine(cmdBuilder.GetInsertCommand().CommandText);
Console.WriteLine(" ");
Console.WriteLine("Delete command Generated by the Command Builder : ");
Console.WriteLine("==================================================");
Console.WriteLine(cmdBuilder.GetDeleteCommand().CommandText);
Console.WriteLine(" ");
//Write out the value in the CustName field before updating the data using the DataSet.
Console.WriteLine("Customer Name before Update : " + CustomersDataSet.Tables["Customers"].Rows[0]["CustName"]);
//Modify the value of the CustName field.
CustomersDataSet.Tables["Customers"].Rows[0]["CustName"] = "Jack";
//Post the data modification to the database.
da.Update(CustomersDataSet, "Customers");
Console.WriteLine("Customer Name updated successfully");
//Close the database connection.
cn.Close();
//Pause
Console.ReadLine();
}
}
}

CodeKeep C# Feed Settembre 30th, 2008
Description: SqlCommandBuilder object to automatically generate the DeleteCommand, the InsertCommand, and the UpdateCommand properties of the SqlCommand object for a SqlDataAdapter object,
Link: http://www.codekeep.net/snippets/a81002c8-495b-429f-b424-996322a7a05b.aspx
using System.Data;
using System.Data.SqlClient;
using System;
namespace Q308507 {
class Class1 {
static void Main(string[] args) {
SqlConnection cn = new SqlConnection();
DataSet CustomersDataSet = new DataSet();
SqlDataAdapter da;
SqlCommandBuilder cmdBuilder;
//Set the connection string of the SqlConnection object to connect
//to the SQL Server database in which you created the sample
//table.
cn.ConnectionString = "Server=server;Database=northwind;UID=login;PWD=password;";
cn.Open();
//Initialize the SqlDataAdapter object by specifying a Select command
//that retrieves data from the sample table.
da = new SqlDataAdapter("select * from CustTest order by CustId", cn);
//Initialize the SqlCommandBuilder object to automatically generate and initialize
//the UpdateCommand, InsertCommand, and DeleteCommand properties of the SqlDataAdapter.
cmdBuilder = new SqlCommandBuilder(da);
//Populate the DataSet by running the Fill method of the SqlDataAdapter.
da.Fill(CustomersDataSet, "Customers");
//Display the Update, Insert, and Delete commands that were automatically generated
//by the SqlCommandBuilder object.
Console.WriteLine("Update command Generated by the Command Builder : ");
Console.WriteLine("==================================================");
Console.WriteLine(cmdBuilder.GetUpdateCommand().CommandText);
Console.WriteLine(" ");
Console.WriteLine("Insert command Generated by the Command Builder : ");
Console.WriteLine("==================================================");
Console.WriteLine(cmdBuilder.GetInsertCommand().CommandText);
Console.WriteLine(" ");
Console.WriteLine("Delete command Generated by the Command Builder : ");
Console.WriteLine("==================================================");
Console.WriteLine(cmdBuilder.GetDeleteCommand().CommandText);
Console.WriteLine(" ");
//Write out the value in the CustName field before updating the data using the DataSet.
Console.WriteLine("Customer Name before Update : " + CustomersDataSet.Tables["Customers"].Rows[0]["CustName"]);
//Modify the value of the CustName field.
CustomersDataSet.Tables["Customers"].Rows[0]["CustName"] = "Jack";
//Post the data modification to the database.
da.Update(CustomersDataSet, "Customers");
Console.WriteLine("Customer Name updated successfully");
//Close the database connection.
cn.Close();
//Pause
Console.ReadLine();
}
}
}

CodeKeep C# Feed Settembre 30th, 2008
CodeKeep C# Feed Settembre 29th, 2008
CodeKeep C# Feed Settembre 29th, 2008
WebReference News Settembre 29th, 2008
Programmers tend to collect utility functions to perform common tasks. In this article we look at some of the key features of the Prototype JavaScript Framework and demonstrate how it can make your life easier. By Rob Gravelle. 0925
CodeKeep C# Feed Settembre 29th, 2008
Description:
How to Get Window NT Logged User Name Using ASP.NET
Link: http://www.codekeep.net/snippets/24ed5597-f3d1-4022-a9ca-af4a20f5eac2.aspx
1) System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
string strName = p.Identity.Name;
[ OR ]
2) string strName = HttpContext.Current.User.Identity.Name.ToString();
[ OR ]
3) string strName = Request.ServerVariables["AUTH_USER"]; //Finding with name
string strName = Request.ServerVariables[5]; //Finding with index

CodeKeep C# Feed Settembre 29th, 2008
Description: Get current windows user - username
Link: http://www.codekeep.net/snippets/47a962c3-eaa1-419f-b2be-7298b69947be.aspx
using System.Security.Principal;
namespace ConsoleApplicationWindowsUser
{
class Program
{
static void Main(string[] args)
{
string a;
a = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
Console.WriteLine(a);
Console.Read();
}
}
}

CodeKeep C# Feed Settembre 28th, 2008
Description: tokenizer with delimeters
Link: http://www.codekeep.net/snippets/cb1142ef-cf37-4f95-b328-7bea2723ac9a.aspx
using System;
using System.Text.RegularExpressions;
public static string[] Tokenize(string equation)
{
Regex RE = new Regex(@"([\+\-\*\(\)\^\\])");
return (RE.Split(equation));
}
public void TestTokenize( )
{
foreach(string token in Tokenize("(y - 3)(3111*x^21 + x + 320)"))
Console.WriteLine("String token = " + token.Trim( ));
}
