<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-801426745050883969</id><updated>2010-06-17T20:29:02.921-07:00</updated><title type='text'>Adam Stirtan</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-4426061201593487849</id><published>2010-06-16T18:52:00.000-07:00</published><updated>2010-06-16T18:52:40.218-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CSS HTML programming'/><title type='text'>Horizontal and vertical alignment with CSS</title><content type='html'>I've been working on a lot of lately on web design in various capacities. One problem I wanted to solve once and for all was centering #div tags either horizontally, vertically or both. Obviously this is a simple enough problem and I'm sure most of you can quickly align horizontally without a headache but vertical sometimes needs some extra considerations.&lt;br /&gt;&lt;br /&gt;Our approach to this will use only CSS and proves to be quite readable later on.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Horizontal alignment&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;.cssClass&lt;br /&gt;{&lt;br /&gt;    margin: 0 auto;&lt;br /&gt;    width: 200px;&lt;br /&gt;    height: 200px;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Well that was easy, we got our div in the middle by setting the margin on the left and right (with a single property) to be automatically determined. Because we specify what the width and height is,the browser can then compute how much area is left on both sides and then divide that in half.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Vertical alignment&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To achieve the vertical alignment we must know in advance the dimensions of the div. Secondly, we set the positioning to be absolute in order to detach the div and have free roam with it. The div is moved horizontally to the center of the window first, but that won't cut it yet as the actual point which is centered is the top left corner. From there, because we know the div dimensions we can offset it to the left and up by half the width and height which centers the actual center in the window center. The only special case here is when the div cannot have a side which is am even number, but we leave that up to the reader to sort out as necessary.&lt;br /&gt;&lt;br /&gt;.cssClass&lt;br /&gt;{&lt;br /&gt;    width: 300px;&lt;br /&gt;    height: 200px;&lt;br /&gt;    position: absolute;&lt;br /&gt;    left: 50%;&lt;br /&gt;    top: 50%;&lt;br /&gt;    margin: -100px 0 0 -150px;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-4426061201593487849?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/4426061201593487849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2010/06/horizontal-and-vertical-alignment-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/4426061201593487849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/4426061201593487849'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2010/06/horizontal-and-vertical-alignment-with.html' title='Horizontal and vertical alignment with CSS'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-423085253162339240</id><published>2010-05-19T05:20:00.000-07:00</published><updated>2010-05-19T05:21:29.519-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Bing'/><category scheme='http://www.blogger.com/atom/ns#' term='VEMap'/><category scheme='http://www.blogger.com/atom/ns#' term='Polygon'/><category scheme='http://www.blogger.com/atom/ns#' term='radius'/><category scheme='http://www.blogger.com/atom/ns#' term='geofence'/><category scheme='http://www.blogger.com/atom/ns#' term='circle'/><category scheme='http://www.blogger.com/atom/ns#' term='WKT'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='VEShape'/><title type='text'>Create radius based circle on Bing maps</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_YkuIrkYKKPg/S_PXYAPea6I/AAAAAAAAC70/mD6SU98Ubug/s1600/VEDrawRadius%5B1%5D.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_YkuIrkYKKPg/S_PXYAPea6I/AAAAAAAAC70/mD6SU98Ubug/s320/VEDrawRadius%5B1%5D.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I've been working with Microsoft Virtual Earth as of lately. One of the requirements for my project has been to create geofence areas based on some latitude longitude which extends out on the map with a given radius. We then use these regions as entry/exit points for moving entities on the map, hence calling them geofences.&lt;br /&gt;&lt;br /&gt;From the picture above, you can see that a geofence has a centroid which is a distinct LatLong object, how this is defined is up to you. In my example I found the coordinate tuple by allowing the user to geocode or reverse geocode, your mileage may vary in how you need to do this. The simplest example I could think of would be the Click event on the VEMap class whereby you simply extract the LatLong by the pixel coordinates.&lt;br /&gt;&lt;br /&gt;So let's assume we have that LatLong object already. The following method will then define a ring around that point with a given radius in either miles or KM according to the radius of the Earth in either KM or miles.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;public static Shape CreateCircle(LatLong Location, double Radius, double EarthRadius)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double lat = Utilities.ToRadians((double)Location.Latitude);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double lon = Utilities.ToRadians((double)Location.Longitude);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double angularDistance = Radius / EarthRadius;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;List&lt;latlong&gt; points = new List&lt;latlong&gt;();&lt;/latlong&gt;&lt;/latlong&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for (int i = 360; i &amp;gt; 0; i--)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double d = Utilities.ToRadians((double)i);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(angularDistance) + Math.Cos(lat) * Math.Sin(angularDistance) * Math.Cos(d));&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double lonRadians = lon + Math.Atan2(Math.Sin(d) * Math.Sin(angularDistance) * Math.Cos(lat), Math.Cos(angularDistance) - Math.Sin(lat) * Math.Sin(latRadians));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;points.Add(new LatLong(Utilities.ToDegrees(latRadians), Utilities.ToDegrees(lonRadians)));&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return new Shape(ShapeType.Polygon, points);&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;From the Utilities class:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;public static double EarthRadiusKM = 6367.0;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static double EarthRadiusMiles = 3956.0;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static double ToRadians(double d)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return d * (Math.PI / 180);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static double ToDegrees(double r)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return r * 180 / Math.PI;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The main thing to recognize in the first method is that we are creating the ring as a collection of 360 LatLong objects around the centroid. Points are defined in decreasing order such that the VEShape returned by the method can be converted easily to WKT to be stored in SQL using a geography data type. If we were to change the loop to start the index at 0 and count to 360, the ring of the Polygon would be invalid and subsequently rejected by SQL (first hand knowledge).&lt;br /&gt;&lt;br /&gt;Finally, we can record in SQL this new geofence by calling a stored procedure "AddGeofence" which I've defined to accept the set of converted points as WKT.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;public static string AddGeofence(Shape Geofence, string ClientID, string Creator)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DbCommand command = GenericDataAccess.CreateCommand();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;command.CommandText = "AddGeofence";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DbParameter param = command.CreateParameter();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.ParameterName = "@ClientID";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.Value = ClientID;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.DbType = DbType.Int32;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;command.Parameters.Add(param);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param = command.CreateParameter();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.ParameterName = "@Name";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.Value = Geofence.Title;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.DbType = DbType.String;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.Size = 250;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;command.Parameters.Add(param);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param = command.CreateParameter();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.ParameterName = "@Description";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.Value = Geofence.Description;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.DbType = DbType.String;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.Size = 250;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;command.Parameters.Add(param);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param = command.CreateParameter();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.ParameterName = "@Geofence";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.Value = GeofenceFunctions.ShapeToWKT(Geofence);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;param.DbType = DbType.String;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;command.Parameters.Add(param);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return GenericDataAccess.ExecuteScalar(command);&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And finally in order to convert the ring to the WKT:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;public static string ShapeToWKT(Shape shape)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string wkt = "";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch (shape.Type)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case ShapeType.Pushpin:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wkt = PushpinToWKT(shape.Points);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case ShapeType.Polyline:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wkt = PolylineToWKT(shape.Points);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case ShapeType.Polygon:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wkt = PolygonToWKT(shape.Points);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;default:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return wkt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;private static string PolygonToWKT(List&lt;latlong&gt; points)&lt;/latlong&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string wkt = "POLYGON((";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for (int i = 0; i &amp;lt; points.Count; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wkt += points[i].Longitude.ToString();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wkt += " ";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wkt += points[i].Latitude.ToString();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (i &amp;lt; points.Count - 1) wkt += ",";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wkt += "))";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return wkt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-423085253162339240?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/423085253162339240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2010/05/create-radius-based-circle-on-bing-maps.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/423085253162339240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/423085253162339240'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2010/05/create-radius-based-circle-on-bing-maps.html' title='Create radius based circle on Bing maps'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_YkuIrkYKKPg/S_PXYAPea6I/AAAAAAAAC70/mD6SU98Ubug/s72-c/VEDrawRadius%5B1%5D.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-4298150993431792418</id><published>2010-04-07T19:01:00.000-07:00</published><updated>2010-04-07T20:07:16.452-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ai'/><category scheme='http://www.blogger.com/atom/ns#' term='neural network'/><category scheme='http://www.blogger.com/atom/ns#' term='ANN'/><category scheme='http://www.blogger.com/atom/ns#' term='self organizing map'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='kohonen network'/><category scheme='http://www.blogger.com/atom/ns#' term='machine learning'/><title type='text'>Self Organizing Map (Kohonen Network)</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_YkuIrkYKKPg/S705PTB0RUI/AAAAAAAAC6g/X-hg-72Jy2g/s1600/defaultcolor.png"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 320px;" src="http://1.bp.blogspot.com/_YkuIrkYKKPg/S705PTB0RUI/AAAAAAAAC6g/X-hg-72Jy2g/s320/defaultcolor.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5457581258411623746" /&gt;&lt;/a&gt;Well its about time I shared something new with everyone. My latest and greatest is an implementation of Kohonen networks or otherwise known as the self organizing map. In this software package I've implemented this network for two tasks using the same algorithm to show the diversity which it can easily manage.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://dl.dropbox.com/u/1211335/SOM.rar"&gt;Download&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the image to the left, you'll see the resulting behavior of the self organizing map tasked with organizing RGB color values. While this is simply a toy problem, it does however serve as a great introduction to the topic.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Secondly (and why the download is so large) I've used the SOM for image clustering. Here I've taken statistical measures of image data sets to abstract away the dependence on the actual dimensions of the images and ensure focus is kept on the information itself. The result is the algorithm being capable of clustering images very accurately. I've included two data sets for you to try, the first of which is a set of cars I found by searching Google's image search and secondly a very large data set of web icons I've used very often in my projects. The result (if set large enough) is a really cool wallpaper all done with AI.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It's coolness in action. Hope you all enjoy.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-4298150993431792418?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/4298150993431792418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2010/04/self-organizing-map-kohonen-network.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/4298150993431792418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/4298150993431792418'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2010/04/self-organizing-map-kohonen-network.html' title='Self Organizing Map (Kohonen Network)'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_YkuIrkYKKPg/S705PTB0RUI/AAAAAAAAC6g/X-hg-72Jy2g/s72-c/defaultcolor.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-5435399792004494122</id><published>2010-03-10T08:28:00.000-08:00</published><updated>2010-03-10T08:59:02.665-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='repeater'/><title type='text'>ASP.Net Nested Repeater with Paging Tutorial</title><content type='html'>In developing web applications using ASP.Net one of the most hated components of programmers is nested repeaters. I covered this topic before another tutorial &lt;a href="http://www.adamstirtan.com/2009/08/aspnet-nested-repeater-tutorial.html"&gt;found here&lt;/a&gt;. What I'd like to show you now is how to extend this further by paging the data source such that groups of elements show on individual pages, similar to how Google's search results are displayed.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_YkuIrkYKKPg/S5fKXGSSLGI/AAAAAAAAC40/bCVlC0448hs/s1600-h/pagednested.png"&gt;&lt;img src="http://4.bp.blogspot.com/_YkuIrkYKKPg/S5fKXGSSLGI/AAAAAAAAC40/bCVlC0448hs/s320/pagednested.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5447044772501007458" style="float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 320px; height: 215px; " /&gt;&lt;/a&gt;&lt;div&gt;We'll start by showing you the desired result. Pictured here is a paged and nested repeater. The outer repeater is a snippet from a discussion board where users can post messages to others. For each of these it is possible to comment on them. This is where we get the nesting requirement, as the comments are specific to the outer repeater items.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;At bottom is a button which allows for navigating to the next page. In this picture we are displaying the first page, if we weren't (and not on the last page) another button would be visible allowing the action "Previous" to be handled.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now that we have the concept let's look at how we accomplish this behavior. It should be clear that we require two distinct data sources and two repeaters. One repeater inside the other.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have created a method which is executed inside the Page_Load(..) method of the web page as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;protected void SetupPaging()&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;PagedDataSource objPds = new PagedDataSource();&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;DataTable dt = //Retrieve outer DataTable type&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;bjPds.DataSource = dt.DefaultView;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;objPds.AllowPaging = true;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;objPds.PageSize = 10;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;objPds.CurrentPageIndex = CurrentPage;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;btPrev.Visible = !objPds.IsFirstPage;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;btNext.Visible = !objPds.IsLastPage;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="white-space: pre; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="white-space: pre; "&gt; DataSet ds = new DataSet();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="white-space: pre; "&gt; ds.Tables.Add(dt);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="white-space: pre; "&gt; ds.Tables.Add(// Get inner repeater DataTable);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="white-space: pre; "&gt; DataColumn dcPosts = ds.Tables[0].Columns["DiscussionPostID"];&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="white-space: pre; "&gt; DataColumn dcReplies = ds.Tables[1].Columns["DiscussionPostID"];&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="white-space: pre; "&gt; ds.Relations.Add(new DataRelation("replies", dcPosts, dcReplies));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;rptDiscussion.DataSource = objPds;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;rptDiscussion.DataBind();&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So lets examine this piece by piece to see how this works. First we instantiate a PagedDataSource object, this type has properties for setting up how many items per page and allows for a DataPager object to control which page it is currently on. The main thing we focus on however is where we set its DataSource property. We set this to the outer table's DefaultView.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Moving on, we create a DataSet, this is going to be the aggregate of both outer and inner tables. To setup the nesting we associate the two tables with a relationship. This relationship assigns which columns in both table relate to each other. In my example image, the relationship was in the outer repeater (Primary Key) and its corresponding discussion post. Each comment was associated with this discussion post and as such we assign the column as "DiscussionPostID". &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Finally we add this association to the DataSet object and bind the repeater to the PagedDataSource. Our repeater is now ready for action, the only thing left is to add some controls for getting the current page. This is a straight forward method which we add to the code behind file as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;public int CurrentPage&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;get&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;object o = this.ViewState["_CurrentPage"];&lt;/div&gt;&lt;div&gt;                if (o == null)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;return 0;&lt;/div&gt;&lt;div&gt;                else&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;return (int)o;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;set&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.ViewState["_CurrentPage"] = value;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That completes our tutorial for now, if you have any questions leave a comment and I'll get back to as best I can.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-5435399792004494122?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/5435399792004494122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2010/03/aspnet-nested-repeater-with-paging.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/5435399792004494122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/5435399792004494122'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2010/03/aspnet-nested-repeater-with-paging.html' title='ASP.Net Nested Repeater with Paging Tutorial'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_YkuIrkYKKPg/S5fKXGSSLGI/AAAAAAAAC40/bCVlC0448hs/s72-c/pagednested.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-8906385521937918923</id><published>2010-03-09T07:38:00.000-08:00</published><updated>2010-03-09T07:52:02.947-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='pso'/><category scheme='http://www.blogger.com/atom/ns#' term='particle swarm'/><category scheme='http://www.blogger.com/atom/ns#' term='slides'/><category scheme='http://www.blogger.com/atom/ns#' term='mario'/><title type='text'>PSO for Evolving Game Playing Agents</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.glenharris.co.uk/Images/www.the-junkyard.net_images_characters_halo2_grunt.jpg_SPLASH.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 374px;" src="http://www.glenharris.co.uk/Images/www.the-junkyard.net_images_characters_halo2_grunt.jpg_SPLASH.jpg" border="0" alt="" /&gt;&lt;/a&gt;Tomorrow I will be giving my final presentation on the progress of my computer science thesis. The title of my paper is 'Particle Swarm Optimization for Evolving Game Playing Agents' and focuses on implementing PSO for the game of Super Mario Bros. As part of this presentation I've prepared a new set of PSO slides which walks through some background information and the details on how it is applied to games.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://dl.dropbox.com/u/1211335/Blog/PSOAgentSlides.rar"&gt;Download Slides&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;My paper will attempt to demonstrate the viability for PSO game agents in a generalized way which can be applied to any game type. I've given high level examples of how this can work for the game of Checkers and a brief overview for how it would be applied to a 3D first person shooter such as Halo. While these components are not implemented, it was the goal of the project to rather develop a method for PSO which simply functioned for games.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The result, in my opinion is astounding. I've posted videos before of the Mario PSO agent in action. My only regret is that I think I was a little late to the Mario competition party and I won't be able to compete this year. It was rumored that during the next round they will be introducing water to the game. I'm confident in the algorithm to be adaptable, more so than static hard coded search strategies some other people tried. Perhaps I'll get my chance then.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Happy coding! Keep fit and have fun.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-8906385521937918923?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/8906385521937918923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2010/03/pso-for-evolving-game-playing-agents.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/8906385521937918923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/8906385521937918923'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2010/03/pso-for-evolving-game-playing-agents.html' title='PSO for Evolving Game Playing Agents'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-8207818251472534750</id><published>2010-02-17T16:07:00.000-08:00</published><updated>2010-02-17T16:16:51.087-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='seminar'/><category scheme='http://www.blogger.com/atom/ns#' term='neural network'/><category scheme='http://www.blogger.com/atom/ns#' term='cascade correlation'/><category scheme='http://www.blogger.com/atom/ns#' term='slides'/><category scheme='http://www.blogger.com/atom/ns#' term='ANN'/><category scheme='http://www.blogger.com/atom/ns#' term='BP'/><category scheme='http://www.blogger.com/atom/ns#' term='machine learning'/><category scheme='http://www.blogger.com/atom/ns#' term='back propagation'/><title type='text'>Cascade Correlation Seminar</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_YkuIrkYKKPg/S3yFADDXbJI/AAAAAAAACzY/FSrM97_gNiM/s1600-h/CascadeNet2%5B1%5D.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_YkuIrkYKKPg/S3yFADDXbJI/AAAAAAAACzY/FSrM97_gNiM/s320/CascadeNet2%5B1%5D.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5439368685822635154" /&gt;&lt;/a&gt;I thought I would make available some presentation slides I have created recently. I will be giving a presentation in my course for artificial neural networks tomorrow on cascade correlation.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://dl.dropbox.com/u/1211335/Blog/Cascade%20Correlation.ppt"&gt;Download Slides&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For those unacquainted with cascade correlation it is a dynamic neural network which as it is processing determines its own topology. Networks begin with only input and output layers, and as necessary hidden units are introduced to the network.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The process requires to back propagation of error signals and often results in very unique solutions to problems. Cascade correlation's learning process is many times quicker than traditional back propagation, but in smaller problems its accuracy suffers. However, due to its dynamical creation, it tends to scale to much larger problems more efficiently while maintaining its break neck speeds of classification.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It's something I would like to experiment with over the summer once things calm down a bit. There are a few unexplored areas of study involved which I think potential papers are lurking.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-8207818251472534750?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/8207818251472534750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2010/02/cascade-correlation-seminar.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/8207818251472534750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/8207818251472534750'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2010/02/cascade-correlation-seminar.html' title='Cascade Correlation Seminar'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_YkuIrkYKKPg/S3yFADDXbJI/AAAAAAAACzY/FSrM97_gNiM/s72-c/CascadeNet2%5B1%5D.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-5917376271707522591</id><published>2010-01-04T19:23:00.000-08:00</published><updated>2010-02-17T16:37:51.594-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='genetic algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='ai'/><category scheme='http://www.blogger.com/atom/ns#' term='neural network'/><category scheme='http://www.blogger.com/atom/ns#' term='pso'/><category scheme='http://www.blogger.com/atom/ns#' term='particle swarm'/><category scheme='http://www.blogger.com/atom/ns#' term='ANN'/><category scheme='http://www.blogger.com/atom/ns#' term='evolution'/><category scheme='http://www.blogger.com/atom/ns#' term='xna'/><category scheme='http://www.blogger.com/atom/ns#' term='neural net'/><category scheme='http://www.blogger.com/atom/ns#' term='ga'/><title type='text'>Evolutionary Neural Networks using Genetic Algorithms and Particle Swarm Optimization in XNA</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_YkuIrkYKKPg/S0Ky-eYFP5I/AAAAAAAACyc/bKl2aM6XDs0/s1600-h/Evo+Tanks.png"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 250px;" src="http://3.bp.blogspot.com/_YkuIrkYKKPg/S0Ky-eYFP5I/AAAAAAAACyc/bKl2aM6XDs0/s320/Evo+Tanks.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5423093687683202962" /&gt;&lt;/a&gt;I've finished my XNA simulation for my machine learning course this previous semester and am posting my resulting source code for all those interested. The project was an open ended venture in to machine learning. I chose to implement evolutionary neural networks and perform a comparative analysis between two biologically inspired algorithms as the basis for the neural network's weight adjustments.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://dl.dropbox.com/u/1211335/Blog/EvoNeuralNetPSOGA.zip"&gt;Download Source Code&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The simulation involves no user interaction beyond the included Settings.ini file where parameters of the simulation can be adjusted. This includes learning rates, PSO and GA settings and how long the simulation runs per generation.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If someone is looking for a proper implementation of a neural network in C# one can surely be found here which could be used in any area of necessity, there is nothing specific to this project.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Using just about all fathomable parameters I have found with this experimentation that PSO finds more optimal weights for the neural networks. They are found faster and retainment of these solutions are better compared to GA. However it should be noted that adaptive mutation is not implemented; that approach would likely increase the chances for GA to consistently compete in later generations.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-5917376271707522591?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/5917376271707522591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2010/01/evolutionary-neural-networks-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/5917376271707522591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/5917376271707522591'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2010/01/evolutionary-neural-networks-using.html' title='Evolutionary Neural Networks using Genetic Algorithms and Particle Swarm Optimization in XNA'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_YkuIrkYKKPg/S0Ky-eYFP5I/AAAAAAAACyc/bKl2aM6XDs0/s72-c/Evo+Tanks.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-6923970656519767160</id><published>2009-11-28T20:14:00.000-08:00</published><updated>2009-12-07T18:12:35.548-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='genetic algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='pso'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='xna'/><category scheme='http://www.blogger.com/atom/ns#' term='machine learning'/><category scheme='http://www.blogger.com/atom/ns#' term='ga'/><title type='text'>Evolutionary Tanks</title><content type='html'>Here is the latest video from my machine learning course. This is my term project where I use evolutionary algorithms for weight updates in an artificial neural network. It was written to simulate a game for a better visual understanding of the learning capabilities. More statistics are going to be included, but I thought I'd share with everyone and bask in the glory that the learning is in fact taking place.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Blue tanks update using a genetic algorithm and red tanks use particle swarm optimization. This is a snapshot of several successive generations starting from the beginning  all the way to where over fitting has occurred.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once I clean up the source code more I'll share it here as well.&lt;div&gt;&lt;br /&gt;&lt;object width="640" height="505"&gt;&lt;param name="movie" value="http://www.youtube.com/v/7D-f76v6Z5s&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;rel=0"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/7D-f76v6Z5s&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-6923970656519767160?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/6923970656519767160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/11/evolutionary-tanks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/6923970656519767160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/6923970656519767160'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/11/evolutionary-tanks.html' title='Evolutionary Tanks'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-3646661087545604704</id><published>2009-11-27T17:14:00.003-08:00</published><updated>2009-11-27T17:19:06.763-08:00</updated><title type='text'>Engagement Photos</title><content type='html'>Here's a quick gallery of some of recently taken engagement photos. They turned out really well, by that I mean of course I don't look like an idiot in all of them.&lt;div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_YkuIrkYKKPg/SxB54h7qr0I/AAAAAAAAB2k/ss8qMgdZIiw/s1600/A%2BA-Engagement-137.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 134px; height: 200px;" src="http://3.bp.blogspot.com/_YkuIrkYKKPg/SxB54h7qr0I/AAAAAAAAB2k/ss8qMgdZIiw/s200/A%2BA-Engagement-137.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5408957164560232258" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_YkuIrkYKKPg/SxB54d-Rl-I/AAAAAAAAB2c/-ZqYby_-GJs/s1600/A%2BA-Engagement-9.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 134px; height: 200px;" src="http://1.bp.blogspot.com/_YkuIrkYKKPg/SxB54d-Rl-I/AAAAAAAAB2c/-ZqYby_-GJs/s200/A%2BA-Engagement-9.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5408957163497428962" /&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); -webkit-text-decorations-in-effect: none; "&gt;&lt;/span&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_YkuIrkYKKPg/SxB530VWV4I/AAAAAAAAB2E/63sWvMllB3o/s1600/A%2BA-Engagement-56.jpg"&gt;&lt;img src="http://4.bp.blogspot.com/_YkuIrkYKKPg/SxB530VWV4I/AAAAAAAAB2E/63sWvMllB3o/s200/A%2BA-Engagement-56.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5408957152319920002" style="float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 200px; height: 134px; " /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_YkuIrkYKKPg/SxB54MK6-fI/AAAAAAAAB2M/kxvw_wqjzQg/s1600/A%2BA-Engagement-121.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px; height: 134px;" src="http://1.bp.blogspot.com/_YkuIrkYKKPg/SxB54MK6-fI/AAAAAAAAB2M/kxvw_wqjzQg/s200/A%2BA-Engagement-121.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5408957158718634482" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-3646661087545604704?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/3646661087545604704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/11/engagement-photos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/3646661087545604704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/3646661087545604704'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/11/engagement-photos.html' title='Engagement Photos'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_YkuIrkYKKPg/SxB54h7qr0I/AAAAAAAAB2k/ss8qMgdZIiw/s72-c/A%2BA-Engagement-137.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-6035193880553746535</id><published>2009-11-25T08:06:00.001-08:00</published><updated>2009-11-25T08:13:38.998-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='seminar'/><category scheme='http://www.blogger.com/atom/ns#' term='pso'/><category scheme='http://www.blogger.com/atom/ns#' term='powerpoint'/><category scheme='http://www.blogger.com/atom/ns#' term='particle swarm'/><category scheme='http://www.blogger.com/atom/ns#' term='slides'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='machine learning'/><title type='text'>Particle Swarm Optimization Tutorial Slides</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_YkuIrkYKKPg/Sw1XCiPYSSI/AAAAAAAAB18/MLh9tJnyOb8/s1600/psoslides.png"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_YkuIrkYKKPg/Sw1XCiPYSSI/AAAAAAAAB18/MLh9tJnyOb8/s320/psoslides.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5408074428604500258" /&gt;&lt;/a&gt;&lt;div&gt;Tomorrow marks the day of a seminar I will be holding in my &lt;a href="http://www.cosc.brocku.ca/Offerings/4P76/"&gt;Machine Learning&lt;/a&gt; course at &lt;a href="http://www.cosc.brocku.ca/"&gt;Brock University&lt;/a&gt;. I have made my power point presentation slides available to all those interested. It provides an overview of how the optimization technique is formulated from biological inspirations to algorithm implementation to applications and examples. It features short videos found on the Internet and a sample video of my &lt;a href="http://www.youtube.com/watch?v=QZDI5-5QAFE"&gt;Mario PSO agent&lt;/a&gt; in its latest form.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is targeted to a person with no such familiarity in PSO with a background in computer science or at least a passion for artificial intelligence.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://dl.dropbox.com/u/1211335/AdamStirtan-PSO.ppt"&gt;Download Presentation Slides&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-6035193880553746535?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/6035193880553746535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/11/particle-swarm-optimization-tutorial.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/6035193880553746535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/6035193880553746535'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/11/particle-swarm-optimization-tutorial.html' title='Particle Swarm Optimization Tutorial Slides'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_YkuIrkYKKPg/Sw1XCiPYSSI/AAAAAAAAB18/MLh9tJnyOb8/s72-c/psoslides.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-578551900525102070</id><published>2009-11-21T16:26:00.001-08:00</published><updated>2009-11-21T16:36:31.157-08:00</updated><title type='text'>PSO Agent</title><content type='html'>Tonight I've organized my presentation for this coming Thursday. I will be holding a seminar in Machine Learning giving a tutorial on particle swarm optimization. As a part included in the presentation I'm demonstrating my Mario agent. Here is the latest video included in the slides. Note: It is still a work in progress but is clearly miles ahead of the last video which was posted.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The main difference between the two videos is this agent is being optimized in a very high dimensional space compared to the first one.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;object width="640" height="505"&gt;&lt;param name="movie" value="http://www.youtube.com/v/QZDI5-5QAFE&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;rel=0"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/QZDI5-5QAFE&amp;amp;hl=en_US&amp;amp;fs=1&amp;amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-578551900525102070?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/578551900525102070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/11/pso-agent.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/578551900525102070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/578551900525102070'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/11/pso-agent.html' title='PSO Agent'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-5525358068486708428</id><published>2009-11-19T20:30:00.000-08:00</published><updated>2009-11-19T20:35:53.448-08:00</updated><title type='text'>Automatic Torrent Starting with Dropbox and uTorrent</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_YkuIrkYKKPg/SwYcREE_2rI/AAAAAAAAB1c/pLK8XpoonwM/s1600/torrent.png"&gt;&lt;/a&gt;Here is just a quick tip for simplifying things a bit. Users of popular torrent client uTorrent can use their Dropbox (&lt;a href="http://www.dropbox.com/"&gt;www.dropbox.com&lt;/a&gt;) account to automatically start torrents while away from their PC.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;1. Create a folder in your Dropbox where you will put .torrent files&lt;/div&gt;&lt;div&gt;2. Enable this setting in the Preferences for uTorrent&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_YkuIrkYKKPg/SwYcREE_2rI/AAAAAAAAB1c/pLK8XpoonwM/s1600/torrent.png"&gt;&lt;img src="http://4.bp.blogspot.com/_YkuIrkYKKPg/SwYcREE_2rI/AAAAAAAAB1c/pLK8XpoonwM/s400/torrent.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5406039482182916786" style="float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 400px; height: 345px; " /&gt;&lt;/a&gt;Now whenever you put a torrent in that folder, your home PC will sync through Dropbox and uTorrent will load the torrent file.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For those with iPhones and Dropbox, well, I don't need to tell you about the potential here.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-5525358068486708428?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/5525358068486708428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/11/automatic-torrent-starting-with-dropbox.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/5525358068486708428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/5525358068486708428'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/11/automatic-torrent-starting-with-dropbox.html' title='Automatic Torrent Starting with Dropbox and uTorrent'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_YkuIrkYKKPg/SwYcREE_2rI/AAAAAAAAB1c/pLK8XpoonwM/s72-c/torrent.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-781593317383630971</id><published>2009-11-10T06:23:00.001-08:00</published><updated>2009-11-10T06:31:43.361-08:00</updated><title type='text'>Image Posterization</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_YkuIrkYKKPg/Svl5K7kAcOI/AAAAAAAAB0U/3EMvKB9oLlo/s1600-h/Posterization.png"&gt;&lt;/a&gt;Last night I decided to change my wallpaper. I usually keep something for a really long time on there that I absolutely love. So every now and then I need to keep it fresh. I settled on a cell shaded render of Master Chief from Halo 3 and that got my interested in making my own. My friend Jake is the Jesus of non photo-realistic rendering (NPR) so I set out to get some answers. (Side note: you can check out his work &lt;a href="http://sites.google.com/site/jestermax/"&gt;here&lt;/a&gt;)&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It turns out that 2D image's aren't really turned in to cell shaded, that's more a 3D approach. Perhaps I should have listened more when Jake added cell shading to our ray tracer last year, but that's how it goes, I never listen to anyone. What I was looking for if anything at all was called posterization.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So I checked out the wiki page, I did a Google search and finally got a complete idea of how it's done. Then, I quickly hammered together a little C# application which implements the posterization algorithm.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here are my results. In honor of Jake, I used his picture, I'm sure he'll be mad, but that's the point. The slider parameter controls how many areas of colors are to be seen. As far as I can tell it looks identical to Photoshop's Posterize filter.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_YkuIrkYKKPg/Svl5K7kAcOI/AAAAAAAAB0U/3EMvKB9oLlo/s1600-h/Posterization.png"&gt;&lt;img src="http://3.bp.blogspot.com/_YkuIrkYKKPg/Svl5K7kAcOI/AAAAAAAAB0U/3EMvKB9oLlo/s400/Posterization.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5402482456701989090" style="float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 400px; height: 222px; " /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Iif I can figure out how to upload files to Blogger I'll share the source code with everyone. It's really quite simple. But now, on to better things, like coffee and wedding photographers.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-781593317383630971?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/781593317383630971/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/11/image-posterization.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/781593317383630971'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/781593317383630971'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/11/image-posterization.html' title='Image Posterization'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_YkuIrkYKKPg/Svl5K7kAcOI/AAAAAAAAB0U/3EMvKB9oLlo/s72-c/Posterization.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-3792041081725934463</id><published>2009-11-04T10:44:00.000-08:00</published><updated>2009-11-09T19:45:46.464-08:00</updated><title type='text'>Proof of Concept Video</title><content type='html'>This is the first video of the particle swarm model being applied to controlling Mario. It simply serves as a proof of concept that my model does in fact work. The decision making is still very early and lots more work is still on-going. I just thought I'd share with you all the fact that this all hasn't been a complete waste of effort.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So without any further fluff, this is my first draft of my Mario artificial intelligence being controlled entirely using the particle swarm optimization model.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;object width="640" height="505"&gt;&lt;param name="movie" value="http://www.youtube.com/v/MlPLUbyX_nU&amp;hl=en&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/MlPLUbyX_nU&amp;hl=en&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-3792041081725934463?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/3792041081725934463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/11/proof-of-concept-video.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/3792041081725934463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/3792041081725934463'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/11/proof-of-concept-video.html' title='Proof of Concept Video'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-4221773299569867265</id><published>2009-10-28T20:02:00.000-07:00</published><updated>2009-10-29T06:26:02.999-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='pso'/><category scheme='http://www.blogger.com/atom/ns#' term='particle swarm'/><category scheme='http://www.blogger.com/atom/ns#' term='mario'/><category scheme='http://www.blogger.com/atom/ns#' term='optimization'/><category scheme='http://www.blogger.com/atom/ns#' term='dimensions'/><title type='text'>Swarm Dimensionality</title><content type='html'>I've been racking my brain as of late with this Mario particle swarm. There are certain challenges in representing Mario's world in a way that particles can optimize a path for him. Particle swarms are meant for large search spaces where dimensionality is high. What I mean by that exactly is if an equation had multi variables and you need to find an approximate solution to that equation, you will be required to find values for all the variables which produces the best result. Consider the following equation:&lt;br /&gt;&lt;br /&gt;a^2 * (b^c) - ((d + 7*ln(e)) / 3f * f^a)&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now I just randomly (not actually random of course) wrote that off the top of my head. Suppose you want to find values for the set of variables S = {a, b, c, d, e, f} which maximizes or minimizes the equation, which in other terms is optimization of its variables.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A particle swarm could easily be used, also perhaps a genetic algorithm, or many other methods. In the above equation there are a finite number of dimensions, in fact the cardinality of S. This directly means that particles will be flying around in 6 dimensional space attempting to find its optimal variable.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So, the problem I have been working on is how to represent Mario in a high dimensional manner such that particles can optimize the space. Over a coffee on the weekend I finally got it, so I'd like to share what I discovered.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Mario, if controlled by a human would have 5 possible buttons which can be pressed. Which are down, left, right, jump and speed. To control as an AI entity, we must make a decision and represent the next action as a series of boolean values where true means press it, false means do not. Pretty simple actually. The problem of course is in detection of all possible scenarios in a very short period of time, 40ms to be precise.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What I have come with essentially maps those 5 actions in to 3 dimensions. Imagine a cube where each vertex represents doing one of 2 actions (or not doing either), whether that is move left, jump, shoot, etc. Let's visualize this a little bit more.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 238); -webkit-text-decorations-in-effect: underline; "&gt;&lt;img src="http://4.bp.blogspot.com/_YkuIrkYKKPg/SukLGiluaqI/AAAAAAAABzY/zEPjykF1-ZE/s320/cube.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5397857835372407458" style="float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 320px; height: 230px; " /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt; Now let's say the x axis is the bottom, if a particle was 3 dimensional, it would be a 3-tuple, {x, y, z} where x, y, z are floating point numbers 0 &lt;= x &lt;= 1. Now there are three possibilities for the action on the axis which are left, right, none.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The same principle applies to the other dimensions in the same way. Finally we map values of the particles position in that dimension in the 3 regions. Left would be 0 &lt;= x &lt;= 1/3.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now particles have a representation for the next action! Simple enough right? Well, we're not there yet. We need to make decisions for Mario based off what is going to happen to some extent. So what do we now?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;At each frame which is drawn we know where Mario is, how many enemies are on the screen, where they are and what type they are. Exactly the same you would be able to extract if you were yourself playing the game. So using the most basic principles of calculus we can associate derivatives with enemies such that this simple principle holds:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;for each (Sprite s in Scene)&lt;br /&gt;s(time + 1) = s(time) + (direction * dx)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So there is the basic inference we're going with. Some special cases need to be accounted for however. For instance, a red koopa walks off a platform, but a green koopa turns around. Another more complicated instance is those flowers which come out of pipes. Things like that humans solve using trial and error and the same principle of determining if you think a street light will change to red. So we can handle those cases.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Finally, we need to expand our dimensionality. Seeing as we can represent the next state of Mario's world in 3 dimensions, it should in turn be possible to represent the next+n state using derivatives. This is going to affect particles because they are going to need to optimize across those dimensions. Effectively we can visual this by expanding the cube. Now it's difficult to imagine this, but just for fun let's look at two figures, the 4 dimensional cube and the 5 dimensional cube.&lt;/div&gt;&lt;div&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/div&gt;&lt;div&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/div&gt;&lt;div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_YkuIrkYKKPg/SukOdTxsRII/AAAAAAAABzg/_jbPqK4NkU8/s1600-h/4d+cube.jpg"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 238); -webkit-text-decorations-in-effect: underline; "&gt;&lt;img src="http://1.bp.blogspot.com/_YkuIrkYKKPg/SukOdTxsRII/AAAAAAAABzg/_jbPqK4NkU8/s320/4d+cube.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5397861525067940994" style="float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 320px; height: 305px; " /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;img src="http://4.bp.blogspot.com/_YkuIrkYKKPg/SukOkvQCMwI/AAAAAAAABzo/iyGQg3iYZ_g/s320/5d+cube.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5397861652702049026" style="float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 289px; height: 320px; " /&gt;&lt;span class="Apple-style-span" style="-webkit-text-decorations-in-effect: none; "&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_YkuIrkYKKPg/SukOkvQCMwI/AAAAAAAABzo/iyGQg3iYZ_g/s1600-h/5d+cube.jpg"&gt;&lt;span class="Apple-style-span"  style="color:#000000;"&gt;Left: 4 Dimensions, Right: 5 Dimensions&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So the particles will operate in this multi-dimensional space where each 3-tuple in succession represents one action to take, followed by the next. For instance {x1, y1, z1, x2, y2, z2} would plan ahead two states, while its particles optimized its variables in 6 dimensional space.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I really hope this makes sense. I'm giving a quick presentation to update my status on this project in the coming weeks and will be posting slides with some more details and will go in to more technical details where necessary. Also, I will be posting code as I go. Currently I'm working on some final framework programming which is uninteresting by itself, but something should come shortly where Mario makes forward movement and at least jumps over top gaps and basic enemies.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Sorry for boring you to death, but at least it had some pictures right?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-4221773299569867265?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/4221773299569867265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/10/swarm-dimensionality.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/4221773299569867265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/4221773299569867265'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/10/swarm-dimensionality.html' title='Swarm Dimensionality'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_YkuIrkYKKPg/SukLGiluaqI/AAAAAAAABzY/zEPjykF1-ZE/s72-c/cube.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-6559482938602629563</id><published>2009-10-20T19:55:00.000-07:00</published><updated>2009-10-20T20:05:06.779-07:00</updated><title type='text'>Mario PSO Seminar</title><content type='html'>On Wednesday October 20 I will be holding a small seminar on my thesis project. The problem is developing an artificial intelligence controller for a clone of Super Mario Bros. 3 called &lt;a href="http://www.mojang.com/notch/mario/"&gt;Infinite Mario Bros&lt;/a&gt;. My approach is going to one which had not to my knowledge been explored. My proposed project will implement Mario as a controller using swarm intelligence to guide decision making.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;There is a corresponding artificial intelligence competition held in part by divisions of IEEE and CIG. For a little food for thought, take a look at the previous years winner who demonstrated a very robust solution using an A* method.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-3f555bc8f8b0c9" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http%3A%2F%2Fv20.nonxt5.googlevideo.com%2Fvideoplayback%3Fid%3D003f555bc8f8b0c9%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1282724952%26sparams%3Did%252Citag%252Cip%252Cipbits%252Cexpire%26signature%3D720442D4C57FA791137A059A0E5D3D7DE6BEE634.585B04798ABF7A983E0C41B968DE7A2AACE77AAD%26key%3Dck1&amp;amp;iurl=http%3A%2F%2Fvideo.google.com%2FThumbnailServer2%3Fapp%3Dblogger%26contentid%3D3f555bc8f8b0c9%26offsetms%3D5000%26itag%3Dw160%26sigh%3DQp8XbBkPcYXcs2W0JUVdI5RDGHc&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http%3A%2F%2Fv20.nonxt5.googlevideo.com%2Fvideoplayback%3Fid%3D003f555bc8f8b0c9%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1282724952%26sparams%3Did%252Citag%252Cip%252Cipbits%252Cexpire%26signature%3D720442D4C57FA791137A059A0E5D3D7DE6BEE634.585B04798ABF7A983E0C41B968DE7A2AACE77AAD%26key%3Dck1&amp;iurl=http%3A%2F%2Fvideo.google.com%2FThumbnailServer2%3Fapp%3Dblogger%26contentid%3D3f555bc8f8b0c9%26offsetms%3D5000%26itag%3Dw160%26sigh%3DQp8XbBkPcYXcs2W0JUVdI5RDGHc&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That utilizes a commonly used graph based engine for movement. Many games use the same method which is tried and true. Consider games like Warcraft, Command &amp;amp; Conquer or Halo Wars. Movement of units need to find a shortest path from A to B in real time, which adapts to dynamical changes in the environment.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Needless to say, swarm intelligence will be very different, but hopefully will appear very "intelligent" to those who watch it attempt a level.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I look forward to putting up some videos of builds of the PSO as the come up, current work is focused on engine and physics calculations, so there isn't much to see. Thus, the time is now to subscribe to this RSS feed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Happy coding.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-6559482938602629563?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/6559482938602629563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/10/mario-pso-seminar.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/6559482938602629563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/6559482938602629563'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/10/mario-pso-seminar.html' title='Mario PSO Seminar'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-3054302030930407314</id><published>2009-08-20T13:16:00.000-07:00</published><updated>2010-02-17T16:39:21.549-08:00</updated><title type='text'>Back in the swing</title><content type='html'>September is slowly creeping up, the time at work here is coming to end and things can go back to what I consider to be normal. I'm an academic at heart, a professional student bent on world destruction with weapons of math destruction. My final year as an undergraduate approaches and I've finally found a thesis project in my last few weeks.&lt;br /&gt;&lt;br /&gt;Beyond all the regular curriculum I'm anticipating a vast majority of my time will be devoted to a year long project for my Honors thesis. The official name of it is "Particle swarm optimization for co-evolution of game playing strategies." Which boils down to two things really. First, I'll be playing games for a year essentially, and secondly, my life is essentially now enclosed in an artificial intelligence box. Pursuing my Master's degree will likely lead down the darken hallways of A.I. even further. This is be my first of hopefully many independent musings in the field.&lt;br /&gt;&lt;br /&gt;After I shake off the dust on my brain left from 4 months of work I'm certain I'll get back in the habit of blogging regularly. Lately I've not had the drive with feeling so drained by office monotony, sorry folks. I'm just not cut out for this type of thing.&lt;br /&gt;&lt;br /&gt;This summer was time well spent overall. Although I did not accomplish every goal I set out for myself I do not consider any of it wasted. A large part was invested developing www.simplegps.com for @simmsalex which ended up being a very robust store front built on ASP.NET 3.5. Some other little apps were built for various reasons of less that notable worth.&lt;br /&gt;&lt;br /&gt;Currently I'm spending much time reading on swarm intelligence and psychology/sociology which seems to be a prerequisite for PSO so I'm attempting to get grounded in it before any for loops get written.&lt;br /&gt;&lt;br /&gt;Coming up in September I'll be attending the Ontario Universities Fair (www.ouf.ca) on behalf of Computer Science at @brockuniversity. Hoping to meet some people interested to throw their lives away in pursuit of numbers and if statements like I did, it's nothing but fun.&lt;br /&gt;&lt;br /&gt;That's it for now, subscribe to the feed and wait for me to wander the hallways and tell about life from the inside.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-3054302030930407314?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/3054302030930407314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/08/particle-swarm-optimization-thesis.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/3054302030930407314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/3054302030930407314'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/08/particle-swarm-optimization-thesis.html' title='Back in the swing'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-1186813031132221703</id><published>2009-08-11T05:38:00.001-07:00</published><updated>2010-01-19T15:18:03.409-08:00</updated><title type='text'>Custom SQL Searching for ASP.Net</title><content type='html'>&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;SQL Server (Express or Standard+)  provides integrated services called full-text search for advanced keyword  searches of information. The full-text search is a robust provision  by Microsoft to enable a developer to quickly leverage user searches  in all facets of SQL whether that be from &lt;a href="http://asp.net/" target="_blank"&gt;ASP.NET&lt;/a&gt; or any other language  which provides means of connecting to SQL. Some of the features they  offer with this method are boolean operators, inflection forms, tenses,  word proximity and result ranking. While this all sounds great, I’m  going to take the rougher path and show you how as I have built a custom  searching back-end for my current &lt;a href="http://asp.net/" target="_blank"&gt;ASP.NET&lt;/a&gt; project.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;There are of course advantages  to developing everything yourself. There is nothing more rewarding I  find then learning each step of the way why and how things happen. Your  algorithms can be finely tuned for the task at hand rather than taking  the cookie cutter approach and of course your next project will have  a far shorter stepping stone to cross when the time comes. So let’s  get going with custom SQL searching by taking a look at some likely  familar syntax for selecting data similar to a parametrized value.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;SELECT&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;*&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;FROM&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; TableName &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;WHERE&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; Name &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;LIKE&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;'%value%'&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;This is a simple example of  using the LIKE keyword to return any rows from TableName where the rows  Name column contains the word value. This would include the following  if they existed: “value”, “valued”, “invalue”, etc. The  % is a wildcard value, it means any 0 or more characters, so because  it is before or after, all instances of value are returned.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Now that we have our feet wet,  recall for a moment when you perform a _insert popular search engine  here_ search your results are ranked. Based off your input the engine  displays the results based off some level of assumed relevancy in order  to quicker provide you with exactly what you were looking for. The first  way we’re going to accomplish this is by ranking our results based  off the number of results per row we’ve found. In other words we may  find that a search string appears more than once in a row, that row  will then be ordered higher than rows which contain less instances of  the search string. Ranking is an important feature to strive for because  the LIKE keyword is going to returned a completely unordered table.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;When dealing with the depths  of SQL you may find there are nowhere near as many built in functions  and operations like other languages may provide. Luckily, this is where  the science happens in computer science. To achieve ranked search results  we need to count occurrences, and because we don’t have a built in  method for doing so, we have to build our own.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;In computational complexity  theory, &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Reduction_%28complexity%29" target="_blank"&gt;&lt;span style="font-family:Times New Roman;font-size:100%;color:#0000ff;"&gt;&lt;u&gt;reduction&lt;/u&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt; is a method of transforming one problem  in to another. In this instance we are going to reduce the problem of  counting word instances to the problem of replacing sub-strings in a  string. This may seem odd, but hang on with me for a minute.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;To accomplish this task, we’re  going to build a SQL user defined function (UDF). These are similar  to stored procedures but are instead used internally by stored procedures  to extent functionality. UDF’s can return data by cannot be used to  modify it.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;To create a UDF in Visual Studio  2008:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;1. Open the Server Explorer&lt;br /&gt;2. Expand your database object&lt;br /&gt;3. Right click on the ‘Functions’ folder.&lt;br /&gt;4. Select ‘Add New’ and then select ‘Inline Function’&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;This UDF is going to count  words the number of occurrences of a smaller string inside a larger  string and return that number in the range 0 to n.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;In a nut shell, we are going  to use a little trick here. We are going to use REPLACE() to replace  all instances of the substring with a new substring which is statically  one character larger. Once the REPLACE() has done its work, the new  larger string will be n characters larger than the original. This is  because all occurrances will now be 1 character longer. To find the  number of occurrences we then subtract the length of the longer string  from the original. That will be the n which we return.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;For example:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;String: “London is a rainy  city, but I don’t mind the rain because I take the train”&lt;br /&gt;Substring: “rain”&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;The UDF will modify the String  to become:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;“London is a &lt;b&gt;rainZy&lt;/b&gt;  city, but I don’t mind the &lt;b&gt;rainZ&lt;/b&gt; because I take the &lt;b&gt;trainZ&lt;/b&gt;”&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Length of original string =  74&lt;br /&gt;Length of modified string = 77&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;77 – 74 = 3 = Occurrences  of substring&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Finally for the end of this  part, let’s take a look at the code to implement the word count.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;CREATE&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;FUNCTION&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; dbo&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;WordCount&lt;/span&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;"&gt;@Word  varchar&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#cc66cc;"&gt;20&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;),&lt;/span&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;"&gt;@String  varchar&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#cc66cc;"&gt;1000&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;RETURNS SMALLINT&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;AS&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;BEGIN&lt;/span&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;"&gt;DECLARE  @WordPlusZ varchar&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#cc66cc;"&gt;21&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;SELECT&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; @WordPlusZ &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; @Word &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;+&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;'Z'  &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;"&gt;DECLARE  @DoubleString varchar&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#cc66cc;"&gt;2000&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;SELECT&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; @DoubleString &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;REPLACE&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;@String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;,&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  @Word&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;,&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; @WordPlusZ&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;)  &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;      &lt;span style="font-family:Courier New;font-size:85%;color:#993333;"&gt;&lt;b&gt;RETURN&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; LEN&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;@DoubleString&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;)&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;-&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; LEN&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;@String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#66cc66;"&gt;)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Hopefully that is clear given  my explanation. Feel free to experiment with this code and shoot holes  through it when you realize you can’t use this code for the LIKE keyword.  However, in another part of this series we will expand on this UDF to  enable functionality. The next article will focus on writing a few stored  procedures which will utilize the UDF’s we are writing here and some  others.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Happy coding everyone, follow  me on Twitter to see when new posts arrive.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-1186813031132221703?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/1186813031132221703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/08/custom-sql-searching-for-aspnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/1186813031132221703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/1186813031132221703'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/08/custom-sql-searching-for-aspnet.html' title='Custom SQL Searching for ASP.Net'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-1250270813572558094</id><published>2009-08-11T05:37:00.000-07:00</published><updated>2010-01-19T15:17:40.185-08:00</updated><title type='text'>ASP.Net Nested Repeater Tutorial</title><content type='html'>&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Displaying collections of data  from data sources is a necessity for web applications. There may come  a time when you will want to assemble a DataTable object and bind to  a repeater which will also contain an inside repeater. The nested relationship  would logically be represented in T-SQL by a foreign key relationship  on the referenced tables. The syntax in ASP.Net can sometimes get a  little hairy when attempting this for the first time. I’m going to  walk you through the process and show you how to get this working on  your web application.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Step one is simple, you’re  going to lay out your templates where your repeaters are going to go.  My normal way of doing this is to layout one single instance of the  contents of and then surround that with the necessary&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Now that you have an idea of  how you want things to look, lets build a little code to create the  nested data set for the repeater groups. From the code behind file,  we need a new method which will occur on Page_Load to bind the required  data to the outer repeater.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;protected&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;void&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; Page_Load(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;object&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; sender, EventArgs e)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Bind the data to  repeater only on page load&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;if&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  (&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;!&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;Page.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;IsPostBack&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     {&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;           BindRepeaters()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     }&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;private&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;void&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; BindRepeaters()&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Create a new data  set&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     DataSet  dataSet &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;new&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; DataSet()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;  &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Outter repeater data  source returns a DataTable&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     dataSet.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Tables&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Add&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(&lt;wbr&gt;ProductGroupFunctions.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;GetProdu&lt;wbr&gt;ctGroups&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;())&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Inner repeater data  source also returns a DataTable&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     dataSet.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Tables&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Add&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(&lt;wbr&gt;ProductFunctions.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;GetProducts&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;wbr&gt;)&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;  &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Create foreign key  relationship on tables using ProductGroupID&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     DataColumn  colGroups &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; dataSet.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Tables&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;[&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;0&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;].&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Columns&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;[&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"&lt;wbr&gt;ProductGroupID"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;]&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     DataColumn  colProducts &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; dataSet.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Tables&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;[&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;1&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;].&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Columns&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;[&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"&lt;wbr&gt;ProductGroupID"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;]&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;  &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Group the tables  using the relationship&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     dataSet.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Relations&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Add&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;new&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  DataRelation(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"products"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;, colGroups, colProducts))&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;  &lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Bind the outer repeater  to our created DataSet object&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     rptProductGroup.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;DataSource&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  dataSet&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008080;"&gt;&lt;i&gt;// Allow the Page to  handle DataBind event&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;     Page.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;DataBind&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;So what we’ve done there  is take two DataTables and combined them into logical groups. The example  I’ve shown here assumes that Products belong to ProductGroups inside  your database, which is process of database normalization. Then given  these two sources we’re going to allow the outer repeater to show  only the products which belong to its current repeated group. This looks  something like the following:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;ProductGroup A&lt;br /&gt;Product A1&lt;br /&gt;Product A2&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;ProductGroup B&lt;br /&gt;Product B1&lt;br /&gt;Product B2&lt;br /&gt;Product B3&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Now the final step is to fill  in the labels, hyperlinks, images etc inside your repeaters. The practice  is a little bit more syntactically obscure and I’m sure this is where  a lot of headaches are caused.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;The outer repeater is the basic  one and is not handled any differently than normal repeaters. Here is  the complete example from the grouped products example above in HTML  code.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;asp:repeater runat="server" id="rptProductGroup"&gt;&lt;/asp:repeater&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;itemtemplate&gt;&lt;/itemtemplate&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;/p&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;             &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                 &lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;h2&gt;&lt;asp:label id="lblProductGroup" runat="server" text=""&gt;"&gt;&lt;/asp:label&gt;&lt;/h2&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;             &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;asp:repeater runat="server" id="rptProducts" datasource=""&gt;DataItem).Row.GetChildRows(&amp;quot;&lt;wbr&gt;products&amp;quot;)  %&gt;"&gt;&lt;/asp:repeater&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;itemtemplate&gt;&lt;/itemtemplate&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;/p&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;             &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                 &lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                     &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                     &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                 &lt;/span&gt;&lt;/p&gt;&lt;table&gt;&lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                             &lt;asp:image id="imgProductPicture" runat="server" imageurl=""&gt;DataItem,  &amp;quot;[\&amp;quot;Picture\&amp;quot;]&amp;quot;).ToString() %&gt;"&gt;&lt;/asp:image&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                             &lt;asp:label id="lblProductName" runat="server" text=""&gt;DataItem, &amp;quot;[\&amp;quot;Name\&amp;quot;]&amp;quot;).ToString()  %&gt;"&gt;&lt;/asp:label&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                             &lt;asp:label id="lblPrice" runat="server" text=""&gt;Container.DataItem,  &amp;quot;[\&amp;quot;Price\&amp;quot;]&amp;quot;).ToString())) %&gt;"&gt;&lt;/asp:label&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                             &lt;asp:button id="btnOrder" runat="server" text="Order" postbackurl=""&gt;ProductID=&amp;quot; + DataBinder.Eval(Container.&lt;wbr&gt;DataItem,  &amp;quot;[\&amp;quot;ProductID\&amp;quot;]&amp;quot;).ToString() %&gt;"&gt;&lt;/asp:button&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;                         &lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;             &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Finally to wrap up, you’ll  notice in the outer repeater to fill a Label to show the group we have:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;asp:label id="lblProductGroup" runat="server" text=""&gt;"&gt;&lt;/asp:label&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;In the DataTable we built there  was a corresponding column called “Name” and it’s simple as ever  before to use that column.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;On the inside repeater we need  to perform things differently. First we need to provide the repeater  with a DataSource as always. This going to be changing depending on  which row of the outer repeater is being processed. This is accomplished  inside the &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;DataSource='' &gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Where “products” is in  the name of the DataRelation object we inserted in our custom DataSet.  Finally on inside repeater we need to specify the column names differently.  There could be another column which again titled “Name” which is  union joined by the relationship. As an example of an inner control  we are going to fill a label control’s text value as follows:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;asp:label id="lblProductName" runat="server" text=""&gt;DataItem,  &amp;quot;[\&amp;quot;Name\&amp;quot;]&amp;quot;).ToString() %&gt;"&gt;&lt;/asp:label&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Hopefully this gives you a  starting block to jump from and attempt this yourself. This can be useful  in examples like I’ve demonstrated above, site maps, or any other  collection of collections you may have to represent in ASP.Net.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-1250270813572558094?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/1250270813572558094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/08/aspnet-nested-repeater-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/1250270813572558094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/1250270813572558094'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/08/aspnet-nested-repeater-tutorial.html' title='ASP.Net Nested Repeater Tutorial'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-801426745050883969.post-1048262999956004084</id><published>2009-08-11T05:32:00.000-07:00</published><updated>2009-08-11T05:36:49.424-07:00</updated><title type='text'>C# List SQL databases and add to list</title><content type='html'>&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;You may come across the requirement  to query a system running SQL Server for a list of all possible databases.  From there you may drill down to find a specific database and need to  perform a query on one of the found database’s tables. For both instances  the .net class &lt;b&gt;SqlConnection&lt;/b&gt; can be used in conjunction with  it’s method &lt;b&gt;GetSchema&lt;/b&gt;. Let’s take a look how to write a method  which will return a list of databases provided a server name and SQL  credentials.&lt;/span&gt;&lt;/p&gt;     &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;public&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; List&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&lt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; GetDatabases&lt;br /&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; ServerName, &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; UserName, &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; Password)&lt;br /&gt;{&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  Instantiate returning data structure of database names&lt;/i&gt;&lt;br /&gt;   List&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&lt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; databases &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;new&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; List&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&lt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt;                              &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  Build connection string with parameters&lt;/i&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; connectionString &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;=&lt;br /&gt;      &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"Data Source="&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;+&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; ServerName &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;+&lt;br /&gt;      &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;";UID="&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;+&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; UserName &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;+&lt;br /&gt;      &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;";Password="&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;+&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; Password &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;+&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;";"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;; &lt;/span&gt; &lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;try&lt;br /&gt;   {&lt;br /&gt;      &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Create SqlConnection  object with connection string&lt;/i&gt;&lt;br /&gt;      &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;using&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  (SqlConnection sqlConnection &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;new&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; SqlConnection(&lt;wbr&gt;connectionString))&lt;br /&gt;       {&lt;br /&gt;          sqlConnection.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Open&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;&lt;br /&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Query SQL server  for databases&lt;/i&gt;&lt;br /&gt;          DataTable dt &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; sqlConnection.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;GetSchema&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"&lt;wbr&gt;Databases"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;)&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;&lt;br /&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Close connection  to SQL&lt;/i&gt;&lt;br /&gt;          sqlConnection.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Close&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Iterate the datatable  and parse names&lt;/i&gt;&lt;br /&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;foreach&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  (DataRow dataRow &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;in&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; dt.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Rows&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;)&lt;br /&gt;          {&lt;br /&gt;             databases.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Add&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(dataRow[&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"&lt;wbr&gt;database_name"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;].&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;ToString&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;())&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;          }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  Handle SQL type errors&lt;/i&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;catch&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; (SqlException ex)&lt;br /&gt;   { }&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  Catch all error handler&lt;/i&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;catch&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; (Exception ex)&lt;br /&gt;   { } &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;return&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; databases&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Now, it’s likely that that  return value will be used to populate a drop down list control to allow  the user to select one of the databases the method found. This is a  simple process but I will include it for completeness.&lt;/span&gt;&lt;/p&gt;             &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// User inputs  server name and SQL credentials on form&lt;/i&gt;&lt;br /&gt;List&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&lt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; databases &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; GetDatabases(&lt;br /&gt;   txtServerName.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Text&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;,&lt;br /&gt;   txtUserName.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Text&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;,&lt;br /&gt;   txtPassword.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Text&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;)&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;; &lt;/span&gt; &lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;&lt;br /&gt;&lt;br /&gt;// Clear drop  down list to prevent duplicates&lt;/i&gt;&lt;br /&gt;ddlDatabases.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Items&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Clear&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;;&lt;i&gt;&lt;br /&gt;&lt;br /&gt;// Iterate through  data structure's strings&lt;/i&gt;&lt;br /&gt;foreach&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; db &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;in&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; databases)&lt;br /&gt;{&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  At new string value to drop down list&lt;/i&gt;&lt;br /&gt;   ddlDatabases.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Items&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Add&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(db)&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;Finally, we’re going to write  a method similar to the database query which will return a list of tables  in a specific database. This will use as parameter a string value which  is the name of a database. It assumes that the connection string is  stored after the first method was executed.&lt;/span&gt;&lt;/p&gt;           &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;public&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; List&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&lt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; GetTables(&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; database)&lt;br /&gt;{&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  Instantiate returning data structure of table names&lt;/i&gt;&lt;br /&gt;   List&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&lt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; tables &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;new&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; List&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&lt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#ff0000;"&gt;String&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;  &lt;/span&gt; &lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;try&lt;br /&gt;   {&lt;br /&gt;      &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Create SqlConnection  object with connection string&lt;/i&gt;&lt;br /&gt;      &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;using&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  (SqlConnection sqlConnection &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;new&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; SqlConnection(&lt;wbr&gt;ConnectionString))&lt;br /&gt;       {&lt;br /&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Build SQL query for  tables of a paramaterized database&lt;/i&gt;&lt;br /&gt;          SqlCommand command &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; sqlConnection.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;CreateCommand&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt;   &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;          command.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;CommandText&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;=&lt;br /&gt;            &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"USE "&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;+&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; database &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;+&lt;br /&gt;            &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;" SELECT [name] AS  Name FROM sysobjects WHERE xtype='U'"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;&lt;/span&gt;&lt;/p&gt;                    &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;          sqlConnection.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Open&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;&lt;br /&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Query SQL for table  names and close connection when done&lt;/i&gt;&lt;br /&gt;          DataTable dt &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;=&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;new&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; DataTable()&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;          dt.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Load&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(command.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;ExecuteReader&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(CommandBehavior.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;CloseConnectio&lt;wbr&gt;n&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;))&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#008000;"&gt;;  &lt;/span&gt; &lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;// Iterate datatable  for table names&lt;/i&gt;&lt;br /&gt;         &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;foreach&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;  (DataRow dataRow &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;in&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; dt.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Rows&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;)&lt;br /&gt;          {&lt;br /&gt;             tables.&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;Add&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;(dataRow[&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#666666;"&gt;"Name"&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;].&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0000ff;"&gt;ToS&lt;wbr&gt;tring&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;())&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;          }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  Handle SQL type errors&lt;/i&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;catch&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; (SqlException ex)&lt;br /&gt;   { }&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;i&gt;//  Catch all error handling&lt;/i&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;catch&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; (Exception ex)&lt;br /&gt;   { } &lt;/span&gt; &lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;br /&gt;   &lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#0600ff;"&gt;return&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt; tables&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:100%;"&gt;That combined approach is a  solid method for reliably retrieving initial information from a SQL  server to drill down and execute a query on a specific table.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/801426745050883969-1048262999956004084?l=www.adamstirtan.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adamstirtan.com/feeds/1048262999956004084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adamstirtan.com/2009/08/c-list-sql-databases-and-add-to-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/1048262999956004084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/801426745050883969/posts/default/1048262999956004084'/><link rel='alternate' type='text/html' href='http://www.adamstirtan.com/2009/08/c-list-sql-databases-and-add-to-list.html' title='C# List SQL databases and add to list'/><author><name>Adam Stirtan</name><uri>http://www.blogger.com/profile/15090235033264812958</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07781867508527431089'/></author><thr:total>0</thr:total></entry></feed>