Wednesday, October 12, 2011

Transaction in c#


SqlConnection con = new SqlConnection("Connection String");

     SqlCommand command1 = new SqlCommand(); //properly initiliased command with sql text or procedure name
            SqlCommand command2 = new SqlCommand(); //properly initiliased command with sql text or procedure name

            SqlTransaction trx = conn.BeginTransaction();
            command1.Transaction = trx;
            command2.Transaction = trx;

            try
            {
                command1.ExecuteNonQuery();
                command2.ExecuteNonQuery();
                trx.Commit();
            }
            catch (SqlException ex)
            {
                trx.Rollback();
            }
            finally
            {
                //clean up resources
            }

Tuesday, October 11, 2011

How to Split String


string mystring = "abc,124,cambridge";
string[] arr_String = mystring.Split(new char[] { ',' });//store string in an array
textbox1.Text = arr_String[0].ToString();//display string in textbox of index 0
textbox2.Text = arr_String[1].ToString();
textbox3.Text = arr_String[2].ToString();