Thursday, May 14, 2009

Mapping XML to SQL Tables

I was recently given an file that had over 14,000 lines of XML and was asked to get that XML data into three separate SQL Tables. After a little bit of googling I found this website - which give lots of great examples of how to map an XML file to a sql table.

http://msdn.microsoft.com/en-us/library/aa225754(SQL.80).aspx

One of the features I'd like to highlight is KeepIdentity. This allows you to insert into a table that has Identity Specification set to Yes.

Wednesday, May 6, 2009

Bind DropDownList with SqlDataSource and Custom ListItems

I ran into a small problem earlier today and wanted to make a note of it here in case I forget in the future. I have a dropdownlist that contained a list of about 30 locations. I originally hard coded these locations, but found later on that putting them in a sql table would be a good idea. After I did that I set up the dropdownlist to use the table I just created:


<asp:DropDownList ID="ddlUSERFacilityID" runat="server" AutoPostBack="true" DataSourceID="dsFacilities" DataTextField="FacilityName" DataValueField="FacilityID" >


However I needed to add a "- Select One -" for the users that had either old and invalid facility ids or users who just didn't have one at all and I was stumped. Clicking around a google search landed me this dropdownlist property that solved my problem:


AppendDataBoundItems="true"


So the final control ended up looking like this:

<asp:DropDownList ID="ddlUSERFacilityID" runat="server" onChange="chgColor();" OnSelectedIndexChanged="updateStatus" AutoPostBack="true" DataSourceID="dsFacilities" DataTextField="FacilityName" DataValueField="FacilityID" AppendDataBoundItems="true">

<asp:ListItem Value="SelectOne" Selected="True">- Select One -" </asp:ListItem>

</asp:DropDownList>

Friday, May 1, 2009

Convert HEX color to System.Drawing color

I am working on a data grid at the moment - and one of the requirements of the grid was to have a clickable image as the remove button AND to have the whole row change colors when the image was clicked. In my googling I came across this method:


Protected Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)

e.Item.BackColor = System.Drawing.ColorTranslator.FromHtml("#ADD6FF")

End Sub


I added this to the codebehind for the click event and viola it works perfectly!