• Update Data in one table with a new or Other table

    by Venkata Koppaka | Dec 14, 2009
    Consider the following scenario - 

    You have data in one table which is old, and then you have data in a newer table which is all good.
    If you have to update the old table with new tables data you can take one of these two approaches

        1. Write a SQL Query that does that
        2. Write a program to iterate and update (ah, I know no one does this except for a purely programming guy who doesn't know any of SQL)

    I am going to focus on writing a SQL Query to update the data - 
    I am going to present you with two ways of writing this query

    Here goes the first one-

    1 update OldTable 
    2 set OldTable.DataToBeUpdated = NewTable.DataToBeUpdated 
    3 from 
    4 OldTable, NewTable 
    5 where 
    6 OldTable.SomeId = NewTable.SomeId 


    And then the second,

    1 update 
    2
    3 select NewTable.DataToBeUpdated as new_value, 
    4        OldTable.DataToBeUpdated as old_value 
    5 from      
    6        OldTable inner join NewTable  on OldTable.SomeId = NewTable.SomeId 
    7 where 
    8       NewTable.DataToBeUpdated is not Null --Some Criteria 
    9
    10 set old_value = new_value; 


    Hope this Helps,
    Cheers
    Venkata


    Go comment!
  • Adding Tooltip to Dropdown List Items

    by Venkata Koppaka | Dec 07, 2009

    Here is a way to add tool tips to items in dropdownlist.

     

    1 //Assuming dropdownLis1 is already Bound.       
    2         foreach (ListItem listItem in dropdownList1.Items) 
    3         { 
    4             listItem.Attributes.Add("title", “tooltip text”); 
    5         } 

    Hope this Helps

    Cheers!!!

    Venkata

    Go comment!
  • Using Elmah in your website

    by Venkata Koppaka | Dec 05, 2009

    Off late I have been using many of open-source projects in the websites that I am trying to build.

    Elmah is one among them  - Click Here to know more about Elmah.

    Here is my quick take on how to use Elmah in your website.

    NOTE: This demo application is built using .NET Framework 4.0 and Visual Studio 2010 Beta2.

    To start using Elmah in your website, include Elmah.dll in to your website. Go to the website right-click on the solution and say add reference

    Point to the Elmah.dll that you have downloaded from google code and it as it as a reference in your project.

    Next in your web.config add the following changes. -

    1. Adding Elmah Configuration Section
    1   <configSections> 
    2     <sectionGroup name="elmah"> 
    3       <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/> 
    4       <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/> 
    5       <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/> 
    6     </sectionGroup> 
    7  
    8   </configSections>  

        2. Add Elmah Connection String

    1 <connectionStrings> 
    2     <add name="ElmahConnectionString" connectionString="Data Source=SUBBARAO-PC\SQLEXPRESS;Initial Catalog=ElmahDatabase;Persist Security Info=True;User ID=sa;Password=sql" providerName="System.Data.SqlClient"/> 
    3   </connectionStrings> 

       3. Add Elmah Section to your Web.config

    1 <elmah> 
    2     <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ElmahConnectionString"/> 
    3     <!-- Don't log 404 --> 
    4     <errorFilter> 
    5       <test> 
    6         <equal binding="HttpStatusCode" value="404" valueType="Int32"/> 
    7       </test> 
    8     </errorFilter> 
    9   </elmah> 

       4.  Add Custom Error Page ( Please note that this step is optional) you may redirect the client to a generic error page or let the Yellow Screen of Death be shown. If you choose to include a generic error page, include the following lines in the web.config

    1 <customErrors mode="On" defaultRedirect="~/Error.aspx"/> 

       5. Add HttpHandlers and HttpModules that Elmah needs. -

    1 <httpHandlers> 
    2       <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> 
    3     </httpHandlers> 
    4     <httpModules> 
    5       <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> 
    6     </httpModules> 

     That is all the configuration we need to do to get Elmah up.

    As for an example that accompanies Elmah I wrote the sample that can be downloaded. This is what I wrote to simulate Elmah.

    I added a Button Click method which throws a NotImplemented Exception . When the website is redirected to a generice Error page (Error.aspx in this case). It can tell the client whatever error message we want to convey them.

    Then hit www.yourwebsite.com/elmah.axd to view a error log which would look similar to this

     

    The view details of Elmah would show you exactly the Yellow Screen of Death that your client sees.

    Everything above should get you up and running for using Elmah.

    Phil Haack has an excellent article to secure Elmah here . Scott Hanselman has an article to show you how to use Elmah with ASP.NET MVC here.

    Hope this article helps .

    You can download all the Code for this article here

     

    The Script that is need to be run against a SQL Database could be found here

    Cheers,

    Venkata

    Go comment!