Deepankar's profile.NET Rocks!!!PhotosBlogListsMore Tools Help

Blog


    Talking about the U.S. Fund for UNICEF campaign

     

    The log file for database is full. Back up the transaction log for the database to free up some log space.

    When dealing with MS SQL (not MY SQL) I’ve seen this error message before, but found little help on it out there.
     
    The log file for database db_name is full. Back up the transaction log for the database to free up some log space.
     
    Within the MS SQL Query Analyzer, do this:
    backup log db_name with truncate_only
    go
    dbcc shrinkfile (db_name_log,0)
    go
     
    If anything, this post will be useful for me in the future when one of my MS SQL databases coughs up the error again

    Talking about Blogging: Design Your Own Weblog Application from Scratch Using ASP.NET, JavaScript, and OLE DB

     

    Quote

    Blogging: Design Your Own Weblog Application from Scratch Using ASP.NET, JavaScript, and OLE DB
    The ASP.NET advanced templated controls, such as the DataList and DataGrid, are perfect for many data representation situations. However, when you need the flexibility to render a variety of layouts, the Repeater control is what you need. In this article the author builds a full-featured blog application to illustrate the use of the Repeater and DataList controls that render nested data in a master-detail relationship. He then discusses how to override the default implementations of these controls by adding some client-side JavaScript code that makes the blog more responsive and enhances its usability.

    Paint Ball

    Have started working on a new site www.urbanpaintball.co.nz, very interesting game, where people hit each other with colored balls and pretend to be dead. Can you believe this game has national and international tournaments.
     
    Will keep you posted more on this game as we progress with the site:)

    Convert a DataSet to a String Variable

    Coverts a DataTable into an Excel string.  Use this method to save a datatable as an Excel file.  It loops through each of the DataTables in the DataSet. There is also an option of whether to print the table headers (column names).

    public static string DataSetToString(DataSet dataSet, string title ,  bool printHeaders)
    {
    StringBuilder sb = new StringBuilder();
    // start the excel file headers
    sb.Append("<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" ");
    sb.Append("xmlns=\"http://www.w3.org/TR/REC-html40\"><head><meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">");
    sb.Append("<meta name=ProgId content=Excel.Sheet><meta name=Generator content=\"Microsoft Excel 9\"><!--[if gte mso 9]>");
    sb.Append("<xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + title + "</x:Name><x:WorksheetOptions>");
    sb.Append("<x:Selected/><x:ProtectContents>False</x:ProtectContents><x:ProtectObjects>False</x:ProtectObjects>");
    sb.Append("<x:ProtectScenarios>False</x:ProtectScenarios></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>");
    sb.Append("<x:ProtectStructure>False</x:ProtectStructure><x:ProtectWindows>False</x:ProtectWindows></x:ExcelWorkbook></xml>");
    sb.Append("<![endif]--></head><body><table>");

    // Start the excel worksheet
    sb.Append("</table><table><tr><td colspan=\"4\"><h3><b>" + title + "</b></h3></td></tr></table>");
    sb.Append("</table><table><tr><td></td></tr></table>");

    for (int table = 0; table < dataSet.Tables.Count; table++)
    {
    sb.Append("<table>");
    if (printHeaders)
    {
    sb.Append(string.Format("<TR><td colspan = \"{0}\"><B>{1}</b></td></tr>",
    dataSet.Tables[table].Columns.Count,dataSet.Tables[table].TableName.ToUpper()));
    sb.Append("<TR BgColor = \"#CCCCCC\">");

    for (int iCol = 0; iCol < dataSet.Tables[table].Columns.Count; iCol++)
    {
    sb.Append("<td><b>" + dataSet.Tables[table].Columns[iCol].ColumnName + "</b></td>");
    }
    sb.Append("</TR>");
    }

    for (int iRow = 0; iRow < dataSet.Tables[table].Rows.Count; iRow++)
    {
    sb.Append("<TR>");
    for (int iCol = 0; iCol < dataSet.Tables[table].Columns.Count; iCol++)
    {
    sb.Append("<td>" + dataSet.Tables[table].Rows[iRow][iCol] + "</b></td>");
    }
    sb.Append("<TR>");
    }

    sb.Append("</table><table><tr><td></td></tr></table>");
    }
    return sb.ToString();
    }

    Strip HTML Tags from a String

    The function below will strip the passed string of all HTML Tags.
     
    Usage 
    string StrippedString = StripHTML ( HTMLString )
     
    Public static string StripHTML ( string value )
    {
            // Strip the html tag
            string pattern = "<(.|\n)+?>";
            string strOutput =  string.Empty;
     
            Regex regex = new Regex ( pattern, RegexOptions.IgnoreCase );
     
            // Replace all HTML tag matches with an empty string
            strOutput = regex.Replace(value, string.Empty);
     
            // Replace all < and > with &lt; and &gt;
            strOutput = strOutput.Replace("<", "&lt;");
            strOutput = strOutput.Replace ( ">", "&gt");
     
            return strOutput;       
    }

    Code Snippets

    I will over the next week keep posting a code snippets which are very useful in development of web applications
     
    Keep watching this space.

    Reading Excel Sheets

    So, I've been writing a little app to combine some Excel spreadsheets. These sheets all have header rows, so I cand open them up with an OleDbConnection, do a "SELECT * FROM [Sheet1$]" and go along my merry way. The problem is, two of the columns I need to work with just aren't there. They're on the excel sheet just fine, but my OleDbDataReader finds nothing in those columns on any row. Looking at the sheet, I see that in those columns, there isn't any data for about 12 rows. So, I put in zeros at the top of those columns, and then it works fine.
     
    Is the OleDbConnection really making assumptions about the dataset based on the first row? After much googling and little success, I try to find a definition of the connectionstring, hoping there's some attribute like "rows to scan for schema" I can set, to tell it to actually read my data. Nathan points me to an excellent resource, Connectionstrings.com, and they kindly let me know that I can specify HDR=Yes; to indicate that I have a header row in my sheets, and IMEX=1; which, according to Connectionstrings.com:  tells the driver to always read "intermixed" data columns as text.
     
    Apparently, the two columns in question were, in fact "intermixed" data columns, and once I set that in my connectionstring, all worked fine. 
     
    If you have, for instance, both strings and numerics in one external data column, you can get unexpected results - like some of your data doesn’t show up and the above solution doesn't work for you, then again after a lot of googling and research, i tried to change the registry keys as mentioned in this article External Data - Mixed Data Types
     
    The mixed use of "1" and "Yes" aside, why the hell would your database driver just silently ignore data? I mean, if "intermixed" data columns is an error condition, then have the balls to throw a exception, warning, event log entry, anything. Don't just not work and expect me to magically know where the problem is. I almost reimplemented the whole damn thing using Excel objects and the Office API, and that would've taken me another couple of days. A pox on the Excel team!

    Status Update

    In case your guys are wondering, I'm still alive and will now start posting to this blog regularly. I've been upto some few cool things.. here is a status update

    www.earlylearning.co.nz, www.distributoys.co.nz are live and kicking

    Beta version of www.cityfind.co.nz will be going live by the 15th of this month

    And most importantly I have been working hard on Sid's new site which will have his own blog and photo gallery.

    Where are the devs hanging out

    When I don't know something I'll ask. So, software developers - where is your favorite place to learn about new techniques?

    • MSDN
    • Visual Studio
    • Byte
    • Dr Dobb's
    • Code Magazine
    • Intel Developer Center
    • C-sharpcorner.com
    • VBDotNetHeaven.com
    • MindCracker
    • CodeProject
    • Developers.net
    • CodeHound.com
    • Developer.*

    Where? Where do your colleagues go and you don't?