<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bee Eee Blog &#187; c# SQL ADO.NET</title>
	<atom:link href="http://blog.bee-eee.com/tag/c-sql-adonet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bee-eee.com</link>
	<description>-- C# hints and tips</description>
	<lastBuildDate>Wed, 23 Dec 2009 19:00:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>C# Determining if a column exists in an SQL database using ADO.Net</title>
		<link>http://blog.bee-eee.com/2008/02/15/c-determining-if-a-column-exists-in-an-sql-database-using-adonet/</link>
		<comments>http://blog.bee-eee.com/2008/02/15/c-determining-if-a-column-exists-in-an-sql-database-using-adonet/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 18:49:58 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[c# SQL ADO.NET]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/02/15/c-determining-if-a-column-exists-in-an-sql-database-using-adonet/</guid>
		<description><![CDATA[This information was very difficult to come by. There isn&#8217;t any useful documentation or tutorials that I found. I have to admit that what follows may only be valid for the System.Data.SQLite.SQLiteConnection sql connection. Just as a warning it may or may not work with a different database connection. The idea is that you&#8217;ve changed [...]]]></description>
			<content:encoded><![CDATA[<p>This information was very difficult to come by.  There isn&#8217;t any useful documentation or tutorials that I found.  I have to admit that what follows may only be valid for the <span style="color: darkgreen"> System.Data.SQLite.SQLiteConnection </span> sql connection.  Just as a warning it may or may not work with a different database connection.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0839924992887657";
/* 468x60, created 6/24/08 */
google_ad_slot = "9966844577";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>The idea is that you&#8217;ve changed your database layout and you want test the opened database to make sure the changes are valid.  If they aren&#8217;t then you want to alter the table.  Anyway here is the code</p>
<pre>
DataTable columns = connection.GetSchema("columns");
System.Data.DataRow[] selColumns = columns.Select("COLUMN_NAME='PREVIEW' AND TABLE_NAME='IMAGES'");
if (selColumns.Length == 0)
{
        ExecuteNonQuerySql("ALTER TABLE IMAGES ADD COLUMN PREVIEW BLOB");
}</pre>
<p>The following line gets the schema table that holds all of the columns from every table.</p>
<pre class="code">DataTable columns = connection.GetSchema("columns");</pre>
<p>The following line filters through all of the columns and get&#8217;s just the column with name &#8216;PREVIEW&#8217; and belongs to the table &#8216;IMAGES&#8217;.</p>
<pre class="code">System.Data.DataRow[] selColumns = columns.Select("COLUMN_NAME='PREVIEW' AND TABLE_NAME='IMAGES'");</pre>
<p>If there are any columns that fit the filter than the length of <span style="color: darkgreen">selColumns</span> will be greater than zero.  If it doesn&#8217;t exist than <span style="color: darkgreen">selColumns.Length</span> will be 0 and you know that the column doesn&#8217;t exist.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/02/15/c-determining-if-a-column-exists-in-an-sql-database-using-adonet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

