Wednesday, 26 September 2012

moving items from one listbox to another c# windows application


        List<string> list = new List<string>();
        List<string> l1 = new List<string>();
        private void Form1_Load(object sender, EventArgs e)
        {
            list.Add("hey");
            list.Add("you");
            list.Add("over");
            list.Add("there");

            listBox1.DataSource = list;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RemoveElements();
        }

        private void RemoveElements()
        {
        
            foreach (var item in listBox1.SelectedItems)
            {
                l1.Add(item.ToString());
                list.Remove(item.ToString());
            }

            listBox1.DataSource = null;
            listBox1.DataSource = list;
            listBox2.DataSource = null;
            listBox2.DataSource = l1;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            RemoveElements();
        }

Friday, 31 August 2012

Tuesday, 28 August 2012

update two tables in one statement in SQL


UPDATE Table1
SET Table1.LastName = 'XXXXXX'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '01'

Handle Errors in Global.asax


Let us see an example of how to use the Global.asax to catch unhandled errors that occur at the application level.
To catch unhandled errors, do the following. Add a Global.asax file (Right click project > Add New Item > Global.asax). In the Application_Error() method, add the following code:

C#
 void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
        Exception objErr = Server.GetLastError().GetBaseException();
        string err = "Error in: " + Request.Url.ToString() +
                          ". Error Message:" + objErr.Message.ToString();
       
    }

VB.NET

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs       
        Dim objErr As Exception = Server.GetLastError().GetBaseException()
        Dim err As String = "Error in: " & Request.Url.ToString() & ". Error Message:"& objErr.Message.ToString()
       
    End Sub

Here we make use of the Application_Error() method to capture the error using the Server.GetLastError().

Friday, 24 August 2012

The underlying connection was closed: The connection was closed unexpectedly.” While returning Data Table from WCF service.


I have changed my operation Contract to return Dataset Instead of Data Table
[OperationContract]
DataSet LoadBatchInformation(string Batch);

Tuesday, 21 August 2012

Fixing innerHTML IE9


        var newdiv = document.createElement("div");
        newdiv.innerHTML = "This is for test" ;
        var container = document.getElementById("container");
        container.appendChild(newdiv);