<?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:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8912334</id><updated>2012-05-27T14:50:08.139-07:00</updated><category term='redirection'/><title type='text'>Marc Boizeau's blog</title><subtitle type='html'>You are a developer and work with Oracle and Microsoft technologies? Have a look!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default?start-index=26&amp;max-results=25'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>38</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8912334.post-7170351453793522284</id><published>2009-03-13T08:58:00.000-07:00</published><updated>2009-03-13T09:04:17.251-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='redirection'/><title type='text'>Go to  knol</title><content type='html'>This  blog is now  quite  inactive.&lt;br /&gt;Here:&lt;a href="http://knol.google.com/k/marc-boizeau/marc-boizeau/g6fqt9cl9ver/0#knols"&gt;http://knol.google.com/k/marc-boizeau/marc-boizeau/g6fqt9cl9ver/0#knols&lt;/a&gt;&lt;br /&gt;you will  find  my new articles both in  french and  english. ( about Business intelligence for instance  and DB design )&lt;br /&gt;&lt;br /&gt;Ce  blog est maintenant  inactif, vous trouverez ici :&lt;br /&gt;&lt;a href="http://knol.google.com/k/marc-boizeau/marc-boizeau/g6fqt9cl9ver/0#knols"&gt;http://knol.google.com/k/marc-boizeau/marc-boizeau/g6fqt9cl9ver/0#knols&lt;/a&gt;&lt;br /&gt; mes nouveaux articles en  francais et en anglais  (   Conception de base de données  mais aussi  algorithmes de  compression)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-7170351453793522284?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://knol.google.com/k/marc-boizeau/marc-boizeau/g6fqt9cl9ver/0#knols' title='Go to  knol'/><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/7170351453793522284/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=7170351453793522284&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/7170351453793522284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/7170351453793522284'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2009/03/go-to-knol.html' title='Go to  knol'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-116593092711423355</id><published>2006-12-12T05:38:00.000-08:00</published><updated>2006-12-12T05:42:08.010-08:00</updated><title type='text'>When does  the next bus pass?</title><content type='html'>I work in a remote bussiness center downtown Paris. Last weeks I spend nearly 3 hour a days comuting.&lt;br /&gt;Every evening, I have to wait for a bus and one time out of two it rain cats and dog.&lt;br /&gt;So every evening I check the bus company's web site in order to known at what time the next bus pass to my station.&lt;br /&gt;Late in the evening at Office I have no time to loose! So I decide to speed up this repetitive task:&lt;br /&gt;&lt;br /&gt;A few times ago(lol) I wrote a C# code to perform a web crawling. I used the same technology to code the following extractor. As usual this has been made with VS studio but, use csc.exe (.Net 1.1 framework) to compile it as well. (see previous posts for exact command line)&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Windows.Forms;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Net;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;namespace bus&lt;br /&gt;{&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Summary description for Form1.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;public class Form1 : System.Windows.Forms.Form&lt;br /&gt;{&lt;br /&gt;private System.Windows.Forms.Button button1;&lt;br /&gt;private System.Windows.Forms.RichTextBox richTextBox1;&lt;br /&gt;private System.Windows.Forms.RichTextBox richTextBox2;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Required designer variable.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;private System.ComponentModel.Container components = null;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Use a regular expression to extract informations from a string&lt;br /&gt;/// all matching results are stored in a string array.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;/// &lt;param name="strHTML"&gt;&lt;/param&gt;&lt;br /&gt;/// &lt;param name="r"&gt;&lt;/param&gt;&lt;br /&gt;/// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;private static string [] extractReg(string strHTML,Regex r)&lt;br /&gt;{&lt;br /&gt;Match m;&lt;br /&gt;&lt;br /&gt;String[] results = new String[101];&lt;br /&gt;&lt;br /&gt;// Use the Matches method to find all matches in the input string.&lt;br /&gt;// Loop through the match collection to retrieve all&lt;br /&gt;// matches.&lt;br /&gt;int i=0;&lt;br /&gt;m = r.Match(strHTML);&lt;br /&gt;&lt;br /&gt;for (i=0; (m.Success &amp;&amp;amp;amp;amp; i&lt;100); m =" m.NextMatch())"&gt;&lt;br /&gt;/// Clean up any resources being used.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;protected override void Dispose( bool disposing )&lt;br /&gt;{&lt;br /&gt;if( disposing )&lt;br /&gt;{&lt;br /&gt;if (components != null)&lt;br /&gt;{&lt;br /&gt;components.Dispose();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;base.Dispose( disposing );&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#region Windows Form Designer generated code&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Required method for Designer support - do not modify&lt;br /&gt;/// the contents of this method with the code editor.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;private void InitializeComponent()&lt;br /&gt;{&lt;br /&gt;this.button1 = new System.Windows.Forms.Button();&lt;br /&gt;this.richTextBox1 = new System.Windows.Forms.RichTextBox();&lt;br /&gt;this.richTextBox2 = new System.Windows.Forms.RichTextBox();&lt;br /&gt;this.SuspendLayout();&lt;br /&gt;//&lt;br /&gt;// button1&lt;br /&gt;//&lt;br /&gt;this.button1.Location = new System.Drawing.Point(0, 0);&lt;br /&gt;this.button1.Name = "button1";&lt;br /&gt;this.button1.Size = new System.Drawing.Size(344, 40);&lt;br /&gt;this.button1.TabIndex = 0;&lt;br /&gt;this.button1.Text = "check it ";&lt;br /&gt;this.button1.Click += new System.EventHandler(this.button1_Click);&lt;br /&gt;//&lt;br /&gt;// richTextBox1&lt;br /&gt;//&lt;br /&gt;this.richTextBox1.Location = new System.Drawing.Point(0, 48);&lt;br /&gt;this.richTextBox1.Name = "-";&lt;br /&gt;this.richTextBox1.Size = new System.Drawing.Size(160, 96);&lt;br /&gt;this.richTextBox1.TabIndex = 1;&lt;br /&gt;this.richTextBox1.Text = "-";&lt;br /&gt;//&lt;br /&gt;// richTextBox2&lt;br /&gt;//&lt;br /&gt;this.richTextBox2.Location = new System.Drawing.Point(168, 48);&lt;br /&gt;this.richTextBox2.Name = "-";&lt;br /&gt;this.richTextBox2.Size = new System.Drawing.Size(176, 96);&lt;br /&gt;this.richTextBox2.TabIndex = 1;&lt;br /&gt;this.richTextBox2.Text = "-";&lt;br /&gt;//&lt;br /&gt;// Form1&lt;br /&gt;//&lt;br /&gt;this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;this.ClientSize = new System.Drawing.Size(352, 150);&lt;br /&gt;this.Controls.Add(this.richTextBox1);&lt;br /&gt;this.Controls.Add(this.button1);&lt;br /&gt;this.Controls.Add(this.richTextBox2);&lt;br /&gt;this.Name = "Form1";&lt;br /&gt;this.Text = "Form1";&lt;br /&gt;this.ResumeLayout(false);&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// The main entry point for the application.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;[STAThread]&lt;br /&gt;static void Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(new Form1());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// This is the main method here we call the web pages and extract method&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;/// &lt;param name="sender"&gt;&lt;/param&gt;&lt;br /&gt;/// &lt;param name="e"&gt;&lt;/param&gt;&lt;br /&gt;private void button1_Click(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;System.Net.HttpWebRequest r ;&lt;br /&gt;string strRes;&lt;br /&gt;int count =0;&lt;br /&gt;string [] nbmin ;&lt;br /&gt;&lt;br /&gt;//I found this regular expression which work well for RATP's real time bus position web site&lt;br /&gt;// You will have to change it regarding the information you want to check.&lt;br /&gt;Regex re = new Regex("&gt;(?'1'[0-9]+ mn).*&lt;", RegexOptions.IgnoreCaseRegexOptions.Compiled); // URL with rich querystrings RATP users will pay attention to "ligne" , "dir", standig for direction , "arr" standing for "arret" (los "libdir" and "lib arr") string URL1 ="http://www.ratp.info/horaires/index.php?reseau=BUS&amp;etape=prec_bustram_ssotr&amp;amp;ligne=179&amp;libligne=GARE+DE+ROBINSON+%2F+PONT+DE+SEVRES&amp;amp;dem=dem3&amp;libarr=LA+BOURSIDIERE&amp;amp;libdir=GARE+DE+ROBINSON&amp;act=act_valid&amp;amp;amp;amp;arr=179_5206_5436&amp;dir=A"; string URL2 = "http://www.ratp.info/horaires/index.php?reseau=BUS&amp;etape=prec_bustram_ssotr&amp;amp;ligne=179&amp;libligne=GARE+DE+ROBINSON+%2F+PONT+DE+SEVRES&amp;amp;dem=dem3&amp;libarr=LA+BOURSIDIERE&amp;amp;libdir=PONT+DE+SEVRES&amp;act=act_valid&amp;amp;amp;amp;arr=179_5206_5436&amp;dir=R"; r =(HttpWebRequest)WebRequest.Create(URL1); r.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials ; System.Net.HttpWebResponse rp = (HttpWebResponse)r.GetResponse(); // Gets the stream associated with the response. Stream receiveStream = rp.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader( receiveStream, encode ); Char[] read = new Char[256]; // Reads 256 characters at a time. count = readStream.Read( read, 0, 256 ); strRes =""; while (count &gt; 0)&lt;br /&gt;{&lt;br /&gt;// Dumps the 256 characters on a string .&lt;br /&gt;String str = new String(read,0, count);&lt;br /&gt;strRes +=str;&lt;br /&gt;count = readStream.Read(read, 0, 256);&lt;br /&gt;}&lt;br /&gt;// Releases the resources of the response.&lt;br /&gt;rp.Close();&lt;br /&gt;// Releases the resources of the Stream.&lt;br /&gt;readStream.Close();&lt;br /&gt;&lt;br /&gt;//write the result of the extraction&lt;br /&gt;this.richTextBox1.Text = "Bus 179 en direction de Robinson" + String.Join("\n", extractReg(strRes,re));&lt;br /&gt;&lt;br /&gt;strRes ="";&lt;br /&gt;r.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials ;&lt;br /&gt;r =(HttpWebRequest)WebRequest.Create(URL2);&lt;br /&gt;r.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials ;&lt;br /&gt;rp = (HttpWebResponse)r.GetResponse();&lt;br /&gt;&lt;br /&gt;count =0;&lt;br /&gt;// Gets the stream associated with the response.&lt;br /&gt;receiveStream = rp.GetResponseStream();&lt;br /&gt;encode = System.Text.Encoding.GetEncoding("utf-8");&lt;br /&gt;// Pipes the stream to a higher level stream reader with the required encoding format.&lt;br /&gt;readStream = new StreamReader( receiveStream, encode );&lt;br /&gt;read = new Char[256];&lt;br /&gt;// Reads 256 characters at a time.&lt;br /&gt;count = readStream.Read( read, 0, 256 );&lt;br /&gt;&lt;br /&gt;while (count &gt; 0)&lt;br /&gt;{&lt;br /&gt;// Dumps the 256 characters on a string .&lt;br /&gt;String str = new String(read,0, count);&lt;br /&gt;strRes +=str;&lt;br /&gt;count = readStream.Read(read, 0, 256);&lt;br /&gt;}&lt;br /&gt;// Releases the resources of the response.&lt;br /&gt;rp.Close();&lt;br /&gt;// Releases the resources of the Stream.&lt;br /&gt;readStream.Close();&lt;br /&gt;&lt;br /&gt;re = new Regex("&gt;(?'1'[0-9]+ mn).*&lt;", RegexOptions.IgnoreCaseRegexOptions.Compiled); //write the result this.richTextBox2.Text = "Bus 179 en direction de pont de Sèvres " + String.Join("\n", extractReg(strRes,re)); } } } &lt;/tt&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-116593092711423355?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/116593092711423355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=116593092711423355&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/116593092711423355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/116593092711423355'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2006/12/when-does-next-bus-pass.html' title='When does  the next bus pass?'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-114001619661729966</id><published>2006-02-15T06:58:00.000-08:00</published><updated>2007-04-02T12:38:42.606-07:00</updated><title type='text'>Thanks</title><content type='html'>Hi everybody. &lt;br /&gt;&lt;br /&gt;I didn’t post for a long time on this blog, sorry about this. Today I'm going to take the time to do something:&lt;br /&gt;&lt;br /&gt;A quick ”Hello” to Stéphane, Eric, Eric (yes), Sophiane, Lucky (yes again), Bulent, Thierry, Christophe, Laurent, Fabienne, Sophianne, Michel and Nathalie. I worked with these guys and girls mainly on Oracle and Microsoft technologies for about three years. We made great things together. &lt;br /&gt;&lt;br /&gt;Thanks for everything.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-114001619661729966?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/114001619661729966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=114001619661729966&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/114001619661729966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/114001619661729966'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2006/02/thanks.html' title='Thanks'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-113473939539492926</id><published>2005-12-16T05:23:00.000-08:00</published><updated>2006-01-16T20:33:45.750-08:00</updated><title type='text'>googled2cd966929769ab9</title><content type='html'>This is what google asked me to put on the sitemap feature&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-113473939539492926?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/113473939539492926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=113473939539492926&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/113473939539492926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/113473939539492926'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/12/googled2cd966929769ab9.html' title='googled2cd966929769ab9'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-113354089998833570</id><published>2005-12-02T08:04:00.000-08:00</published><updated>2006-01-19T20:36:48.430-08:00</updated><title type='text'>two lines in the datagrid header</title><content type='html'>Ok, this is  a dirty workaround but it works. &lt;br /&gt;&lt;br /&gt;In a winform datagrid  you can't directly change the columns header height.  is is the workaroun Eric,  a collegue of mine find somewhere on internet : change the datagrid header font size without changing the column header font. &lt;br /&gt;&lt;br /&gt;for instance &lt;br /&gt; System.Drawing.Font f =new System.Drawing.Font("Verdana", &lt;b&gt;15.25F&lt;/b&gt;, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,Convert.ToByte(0));&lt;br /&gt;&lt;br /&gt;                  MyDatagrid.HeaderFont = f;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-113354089998833570?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/113354089998833570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=113354089998833570&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/113354089998833570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/113354089998833570'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/12/two-lines-in-datagrid-header.html' title='two lines in the datagrid header'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-112732387918012432</id><published>2005-09-21T10:30:00.000-07:00</published><updated>2007-01-22T13:42:09.250-08:00</updated><title type='text'>Context saving with persistent datasets</title><content type='html'>&lt;i&gt;This article propose a way to use dataset to  make persistent an arbitrary set of data.in the context of a winform application&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Sometimes  you need to stored datas but you don't think a database is   the right way. &lt;br /&gt;For instance if you want to store the user's context (search criterias,options, the last time he use the application...) in order to set it back the next time  the application is used, you need a specific tool. &lt;br /&gt;To achieve this  you may  use a little  xml file.  &lt;br /&gt;But, most of the time, you don't know exactly what you will need to store in advance. &lt;br /&gt;So defining and changing and changing again the schema of the xml file could be something close to a good headache.&lt;br /&gt;&lt;br /&gt;An idea is to propose a set of methods which adapt the schema inline. &lt;br /&gt;&lt;br /&gt;The microsoft .Net  DataSet object has  two powerfull  methods  ReadXml and WriteXml. &lt;br /&gt;These methods manipulates the datas and also the  schema of the  dataset.&lt;br /&gt;So I  choose  this  object  to implement  my context saving class for winform application.&lt;br /&gt;(It could be easily adapt for a server side use) &lt;br /&gt;&lt;br /&gt;The idea is that when a coder need a  new persistent data, he  use the following syntax:&lt;br /&gt;&lt;br /&gt;Contexte.getSimpleval("MyDataName");&lt;br /&gt;The schema will be changed at the first use and the next time, it will bring back the last setled value.&lt;br /&gt;&lt;br /&gt;When modified, the data is stored like this:&lt;br /&gt;Contexte.setSimpleval("MyNewinformationName", MyStringValue);// the  stored info are here of string type&lt;br /&gt;&lt;br /&gt;If the amount of information is important  data could be sort by collections using the syntaxes:&lt;br /&gt;&lt;br /&gt;getVal(string "MyNewCollectionName","MyNewinformationName")&lt;br /&gt;and &lt;br /&gt;setVal(string "MyNewCollectionName","MyNewinformationName", MyStringValue)&lt;br /&gt;&lt;br /&gt;The "save()" and "load()" methods are called at the begining and at the end  of the application. &lt;br /&gt;(typically the onLoad and onClose  events of the main window). &lt;br /&gt; &lt;br /&gt;Here is the code of the class, please critisize, comment and ask questions!&lt;br /&gt; &lt;br /&gt;&lt;font face = "courrier"&gt;&lt;b&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;namespace MyNamespace&lt;br /&gt;{&lt;br /&gt; /// &amp;lt;summary&amp;gt;&lt;br /&gt; /// The Contexte class is used to make  datas persistant&lt;br /&gt; /// Marc Boizeau&lt;br /&gt; /// Two types of data are managed&lt;br /&gt; ///  - collections: values  identified by a collection name and a field name&lt;br /&gt; ///  - Simple values just identified by a  name &lt;br /&gt; /// &amp;lt;/summary&amp;gt;&lt;br /&gt; public class Contexte&lt;br /&gt; {&lt;br /&gt;  private const string FILE_NAME="Context.xml";&lt;br /&gt;  // context  data  container dataset&lt;br /&gt;  static private DataSet ds;&lt;br /&gt;&lt;br /&gt;  public Contexte()&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  /// &amp;lt;summary&amp;gt;&lt;br /&gt;  /// Retrives the good path for  context &lt;br /&gt;  /// &amp;lt;/summary&amp;gt;&lt;br /&gt;  /// &amp;lt;returns&amp;gt; the context path, string &amp;lt;/returns&amp;gt;&lt;br /&gt;  static private  string getFilePath()&lt;br /&gt;  {&lt;br /&gt;   //to change &lt;br /&gt;   string path= Environment.GetEnvironmentVariable("APPDATA")+"/MyApplication/";&lt;br /&gt;   &lt;br /&gt;   if (!Directory.Exists(path))&lt;br /&gt;    Directory.CreateDirectory(path);&lt;br /&gt;  &lt;br /&gt;   &lt;br /&gt;   path+=FILE_NAME;&lt;br /&gt;&lt;br /&gt;   return path ;&lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;  //load the dataset  with the xml file &lt;br /&gt;  public static  void load()&lt;br /&gt;  {&lt;br /&gt;   if (ds!=null)&lt;br /&gt;    ds = null;&lt;br /&gt;   &lt;br /&gt;   ds = new DataSet("ContexteExpertises");&lt;br /&gt;   &lt;br /&gt;   try&lt;br /&gt;   {&lt;br /&gt;    if (File.Exists(getFilePath()))&lt;br /&gt;     ds.ReadXml( getFilePath(),XmlReadMode.ReadSchema);&lt;br /&gt;   }&lt;br /&gt;   catch(Exception e)&lt;br /&gt;   {// files do  &lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //save the datafile &lt;br /&gt;  public static  void Save()&lt;br /&gt;  {&lt;br /&gt;   if(ds== null)&lt;br /&gt;   {&lt;br /&gt;    ds =new DataSet("ContexteExpertises");&lt;br /&gt;   }&lt;br /&gt;   ds.WriteXml(getFilePath(),XmlWriteMode.WriteSchema);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // retrieve a datatable by its name&lt;br /&gt;  private static DataTable getTable(string TableName)&lt;br /&gt;  {&lt;br /&gt;   DataTable dt;&lt;br /&gt;   if (!ds.Tables.Contains(TableName))&lt;br /&gt;   {&lt;br /&gt;    dt = new DataTable(TableName);&lt;br /&gt;    dt.Columns.Add("NAME");&lt;br /&gt;    dt.Columns.Add("VALUE");&lt;br /&gt;    dt.Constraints.Add("PK",dt.Columns["NAME"],true);&lt;br /&gt;    ds.Tables.Add(dt);&lt;br /&gt;   }&lt;br /&gt;   else&lt;br /&gt;    dt = ds.Tables[TableName];&lt;br /&gt;   return dt;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //retrieves a data by a table name and a field name&lt;br /&gt;  public static string getVal(string TableName, string Entry)&lt;br /&gt;  {&lt;br /&gt;   DataTable dt;&lt;br /&gt;   DataView dv;&lt;br /&gt;   dt = getTable(TableName);&lt;br /&gt;   dv = dt.DefaultView;&lt;br /&gt;&lt;br /&gt;   if (Entry==null)&lt;br /&gt;    Entry=""; &lt;br /&gt;&lt;br /&gt;   dv.RowFilter= " NAME ='" + Entry+ "'";&lt;br /&gt;   //test if exists&lt;br /&gt;   if (dv.Count==0)&lt;br /&gt;   {//if not creates&lt;br /&gt;    DataRow dr =dt.NewRow();&lt;br /&gt;    dr["NAME"]=   Entry;&lt;br /&gt;    dr["VALUE"]="";&lt;br /&gt;    dt.Rows.Add(dr);&lt;br /&gt;   }&lt;br /&gt;   //at this point the entry exist&lt;br /&gt;   return dt.Rows.Find(Entry)["VALUE"].ToString();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // setting a data&lt;br /&gt;  public static void setVal(string TableName, string Entry,string Val)&lt;br /&gt;  {&lt;br /&gt;   DataTable dt;&lt;br /&gt;   DataView dv;&lt;br /&gt;   dt = getTable(TableName);&lt;br /&gt;   dv = dt.DefaultView;&lt;br /&gt;   dv.RowFilter= " NAME ='" + Entry+ "'";&lt;br /&gt;  &lt;br /&gt;   if (Entry==null)&lt;br /&gt;    Entry="";&lt;br /&gt;   &lt;br /&gt;   if (Val==null)&lt;br /&gt;    Val="";&lt;br /&gt;&lt;br /&gt;   //test if exists&lt;br /&gt;   if (dv.Count==0)&lt;br /&gt;   {//if not creates&lt;br /&gt;    DataRow dr =dt.NewRow();&lt;br /&gt;    dr["NAME"]= Entry;&lt;br /&gt;    dr["VALUE"]= "";&lt;br /&gt;    dt.Rows.Add(dr);&lt;br /&gt;   }&lt;br /&gt;   //at this point the entry exists&lt;br /&gt;   dt.Rows.Find(Entry)["VALUE"]=Val;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  /// &amp;lt;summary&amp;gt;&lt;br /&gt;  /// retrieves a simple value&lt;br /&gt;  /// &amp;lt;/summary&amp;gt;&lt;br /&gt;  /// &amp;lt;param name="Entry"&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;  /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;  public static string getSimpleVal(string Entry)&lt;br /&gt;  {&lt;br /&gt;   if (ds==null)&lt;br /&gt;    load();&lt;br /&gt;   return  getVal("SIMPLE", Entry);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  /// &amp;lt;summary&amp;gt;&lt;br /&gt;  /// set a simple value&lt;br /&gt;  /// &amp;lt;/summary&amp;gt;&lt;br /&gt;  /// &amp;lt;param name="Entry"&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;  /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;  public static void  setSimpleVal(string Entry,string val)&lt;br /&gt;  {&lt;br /&gt;   if (ds==null)&lt;br /&gt;    load();&lt;br /&gt;   setVal("SIMPLE", Entry,val);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-112732387918012432?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/112732387918012432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=112732387918012432&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112732387918012432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112732387918012432'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/09/context-saving-with-persistent.html' title='Context saving with persistent datasets'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-112542138591198622</id><published>2005-08-30T09:59:00.000-07:00</published><updated>2005-10-14T04:00:59.890-07:00</updated><title type='text'>.net webservice session</title><content type='html'>Maybe  it is obvious but I've seen the question  on a forum;&lt;br /&gt;Q:"How to make  the session  collection  work for a  .net webservice like  for asp.net? "&lt;br /&gt;&lt;br /&gt;A:"Just put the following before the web method:"&lt;br /&gt;&lt;font face = courrier&gt;[ WebMethod(Description="Desc",EnableSession=true)]&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;thats all folks!&lt;br /&gt;&lt;br /&gt;hope this helps.&lt;br /&gt;&lt;br /&gt;comments are welcome&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ok  I've posted this a few time ago. And it still works. But,  the session collection  is not a real session objectin this  case. It is instanciate just before the web method call, but  I never seen when it is uninstanciate. For instance the "end_session" event never fire! &lt;br /&gt;Also, I experiment troubles while debuging an object stored in this collection  for a web method. &lt;br /&gt;So, use this the least you can and do not expect this to be a good equivalent to the session collection in classical ASP .Net.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-112542138591198622?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/112542138591198622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=112542138591198622&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112542138591198622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112542138591198622'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/08/net-webservice-session.html' title='.net webservice session'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-112531376721527087</id><published>2005-08-29T03:55:00.000-07:00</published><updated>2005-09-21T02:09:41.816-07:00</updated><title type='text'>Winform, Web Services &amp;  credential</title><content type='html'>Just a tip today. &lt;br /&gt;&lt;br /&gt;Last week I built a web service based  application  which needs a  windows authentication. &lt;br /&gt;The schema  was:&lt;br /&gt;A winform client &lt;br /&gt;A group of IIS web services. &lt;br /&gt;An  oracle  database (as alway on this blog lol)&lt;br /&gt;&lt;br /&gt;How could the winform client say to the  web services. "Hey i'm a member of this  windows network,  my login is Jdoe, trust me"&lt;br /&gt;&lt;br /&gt;Ok,  first  I asked my favourite web administrator to configure my IIS application to not allow anonymous users. Exactly like for a classical  ASPX application. &lt;br /&gt;&lt;br /&gt;Then  I changed my web.config file, puting the line :&lt;br /&gt;&amp;lt;authentication mode="Windows" /&amp;gt; &lt;br /&gt;&lt;br /&gt;Ok  IIS was then fine  to authenticate users. &lt;br /&gt;but my Winform webservice client wasn't ready yet. &lt;br /&gt;&lt;br /&gt;In order to be "windowsly" authenticate  a webservice client  need to send  credentials to the server. &lt;br /&gt;The .net framework  provide a secure and elegant way to to that:&lt;br /&gt;&lt;br /&gt;&lt;font  face="courrier"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Net;&lt;br /&gt;....&lt;br /&gt;&lt;br /&gt;MyService.MyWebMethod ws = new MyService.MyWebMethod();&lt;br /&gt;ws.Credentials = &lt;b&gt;CredentialCache.DefaultCredentials&lt;/b&gt;;&lt;br /&gt;...&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;and it works ! &lt;br /&gt;I was then  able to retrieve  informations about my connected users.  For instance&lt;br /&gt;the login :&lt;br /&gt;&lt;font  face="courrier"&gt;&lt;br /&gt;...&lt;br /&gt;strlogin = user.identity.name&lt;br /&gt;...&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;that's all folks! &lt;br /&gt;hope this helps!&lt;br /&gt;Comments are welcome!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-112531376721527087?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/112531376721527087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=112531376721527087&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112531376721527087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112531376721527087'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/08/winform-web-services-credential.html' title='Winform, Web Services &amp;  credential'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-112445845028552243</id><published>2005-08-19T06:32:00.000-07:00</published><updated>2005-08-22T11:06:24.366-07:00</updated><title type='text'>back to work</title><content type='html'>Hello everybody&lt;br /&gt;&lt;br /&gt;I'm back to work! I didn't post  these last three weeks because I was &lt;br /&gt;&lt;a href="http://stranddjerba.freeservers.com/Location.html" target="site"&gt;here&lt;/a&gt; and also  &lt;a href="http://www.edreams.es/edreams/espanol/packages/imageview.jhtml;$sessionid$3MU15LANNYC2LQFIS1WBNWWUVLR4QIV0?image=%2Fimages%2Fgallery%2F4405%2F2_Tunez_KsarGuilane_Desert01.jpg&amp;title=Los+mejores+puertos+del+Mediterr%E1neo&amp;back=%2Fedreams%2Fespanol%2Fso%2Fdettagli%2Fdettagli2.jhtml" target="site"&gt; there&lt;/a&gt; ,I also went to &lt;a href="http://cm1cm2.ceyreste.free.fr/calanques.html"&gt; this place&lt;/a&gt; .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-112445845028552243?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/112445845028552243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=112445845028552243&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112445845028552243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112445845028552243'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/08/back-to-work.html' title='back to work'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-112083629781829041</id><published>2005-07-08T08:24:00.000-07:00</published><updated>2005-07-08T08:24:57.823-07:00</updated><title type='text'>just a link</title><content type='html'>&lt;a title="blog directory" href="http://www.wilsdomain.com/"&gt;&lt;b&gt;Blog Directory&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a title="search for blogs" href="http://www.juaxoo.com/"&gt;&lt;b&gt;Search for Blogs&lt;/b&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-112083629781829041?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/112083629781829041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=112083629781829041&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112083629781829041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/112083629781829041'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/07/just-link.html' title='just a link'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111963156641193542</id><published>2005-06-24T09:42:00.000-07:00</published><updated>2007-02-20T13:44:19.883-08:00</updated><title type='text'>self description</title><content type='html'>Somebody ask for the  code  of  the self descripting  c# code i've done &lt;a href="http://oraclevsmicrosoft.blogspot.com/2005/01/code-generation-and-self-description.html"&gt; a few times ago here&lt;/a&gt; it is :&lt;br /&gt;&lt;br /&gt;&lt;font face="courier"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Windows.Forms;&lt;br /&gt;using System.CodeDom;&lt;br /&gt;using System.CodeDom.Compiler;&lt;br /&gt;using Microsoft.CSharp;&lt;br /&gt;using System.Collections.Specialized;&lt;br /&gt;namespace WindowsApplication2&lt;br /&gt;{&lt;br /&gt;    /// Main form&lt;br /&gt;&lt;br /&gt;    public class Form1 : System.Windows.Forms.Form&lt;br /&gt;    {&lt;br /&gt;  private System.Windows.Forms.Button button2;&lt;br /&gt;  private System.Windows.Forms.Button button1;&lt;br /&gt;  private System.Windows.Forms.Button bt_itself;&lt;br /&gt;  private System.Windows.Forms.RichTextBox rt1;&lt;br /&gt;  private System.Windows.Forms.ListBox listBox1;&lt;br /&gt;        private System.ComponentModel.Container components = null;&lt;br /&gt;&lt;br /&gt;        public Form1()&lt;br /&gt;        {&lt;br /&gt;            //&lt;br /&gt;            // Requis pour la prise en charge du Concepteur Windows Forms&lt;br /&gt;            //&lt;br /&gt;            InitializeComponent();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// Nettoyage des ressources utilisées.&lt;br /&gt;        protected override void Dispose( bool disposing )&lt;br /&gt;        {&lt;br /&gt;            if( disposing )&lt;br /&gt;            {&lt;br /&gt;                if (components != null)&lt;br /&gt;                {&lt;br /&gt;                    components.Dispose();&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            base.Dispose( disposing );&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        #region Code généré par le Concepteur Windows Form&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas&lt;br /&gt;        /// le contenu de cette méthode avec l'éditeur de code.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        private void InitializeComponent() {&lt;br /&gt;   this.listBox1 = new System.Windows.Forms.ListBox();&lt;br /&gt;   this.rt1 = new System.Windows.Forms.RichTextBox();&lt;br /&gt;   this.bt_itself = new System.Windows.Forms.Button();&lt;br /&gt;   this.button1 = new System.Windows.Forms.Button();&lt;br /&gt;   this.button2 = new System.Windows.Forms.Button();&lt;br /&gt;   this.SuspendLayout();&lt;br /&gt;   // &lt;br /&gt;   // listBox1&lt;br /&gt;   // &lt;br /&gt;   this.listBox1.Location = new System.Drawing.Point(24, 360);&lt;br /&gt;   this.listBox1.Name = &amp;quot;listBox1&amp;quot;;&lt;br /&gt;   this.listBox1.Size = new System.Drawing.Size(1016, 108);&lt;br /&gt;   this.listBox1.TabIndex = 3;&lt;br /&gt;   // &lt;br /&gt;   // rt1&lt;br /&gt;   // &lt;br /&gt;   this.rt1.Location = new System.Drawing.Point(24, 16);&lt;br /&gt;   this.rt1.Name = &amp;quot;rt1&amp;quot;;&lt;br /&gt;   this.rt1.Size = new System.Drawing.Size(632, 328);&lt;br /&gt;   this.rt1.TabIndex = 1;&lt;br /&gt;   this.rt1.Text = &amp;quot;richTextBox1&amp;quot;;&lt;br /&gt;   // &lt;br /&gt;   // bt_itself&lt;br /&gt;   // &lt;br /&gt;   this.bt_itself.Location = new System.Drawing.Point(696, 40);&lt;br /&gt;   this.bt_itself.Name = &amp;quot;bt_itself&amp;quot;;&lt;br /&gt;   this.bt_itself.Size = new System.Drawing.Size(72, 24);&lt;br /&gt;   this.bt_itself.TabIndex = 0;&lt;br /&gt;   this.bt_itself.Text = &amp;quot;it self&amp;quot;;&lt;br /&gt;   this.bt_itself.Click += new System.EventHandler(this.bt_itself_Click);&lt;br /&gt;   // &lt;br /&gt;   // button1&lt;br /&gt;   // &lt;br /&gt;   this.button1.Location = new System.Drawing.Point(696, 8);&lt;br /&gt;   this.button1.Name = &amp;quot;button1&amp;quot;;&lt;br /&gt;   this.button1.Size = new System.Drawing.Size(72, 24);&lt;br /&gt;   this.button1.TabIndex = 0;&lt;br /&gt;   this.button1.Text = &amp;quot;genere&amp;quot;;&lt;br /&gt;   this.button1.Click += new System.EventHandler(this.button1_Click);&lt;br /&gt;   // &lt;br /&gt;   // button2&lt;br /&gt;   // &lt;br /&gt;   this.button2.Location = new System.Drawing.Point(696, 72);&lt;br /&gt;   this.button2.Name = &amp;quot;button2&amp;quot;;&lt;br /&gt;   this.button2.Size = new System.Drawing.Size(72, 24);&lt;br /&gt;   this.button2.TabIndex = 4;&lt;br /&gt;   this.button2.Text = &amp;quot;compile&amp;quot;;&lt;br /&gt;   this.button2.Click += new System.EventHandler(this.button2_Click);&lt;br /&gt;   &lt;br /&gt;   // &lt;br /&gt;   // Form1&lt;br /&gt;   // &lt;br /&gt;   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;   this.ClientSize = new System.Drawing.Size(1032, 526);&lt;br /&gt;   this.Controls.Add(this.button2);&lt;br /&gt;   this.Controls.Add(this.listBox1);&lt;br /&gt;   this.Controls.Add(this.rt1);&lt;br /&gt;   this.Controls.Add(this.button1);&lt;br /&gt;   this.Controls.Add(this.bt_itself);&lt;br /&gt;   this.Name = &amp;quot;Form1&amp;quot;;&lt;br /&gt;   this.Text = &amp;quot;Form1&amp;quot;;&lt;br /&gt;   this.Load += new System.EventHandler(this.Form1_Load);&lt;br /&gt;   this.ResumeLayout(false);&lt;br /&gt;  }&lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;        /// Point d'entrée principal de l'application.&lt;br /&gt;        [STAThread]&lt;br /&gt;        static void Main()&lt;br /&gt;        {&lt;br /&gt;            Application.Run(new Form1());&lt;br /&gt;        }&lt;br /&gt;// methode de base &lt;br /&gt;  string join(string[] arr,string sep)&lt;br /&gt;  {string strReturn=&amp;quot;&amp;quot; ;&lt;br /&gt;   foreach (string elt in arr)&lt;br /&gt;    strReturn += elt+sep;&lt;br /&gt;   strReturn.Substring(0,strReturn.Length-sep.Length);&lt;br /&gt;     &lt;br /&gt;   return strReturn;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  void seekandreplace(string[] arr,string strSrc,string strReplace)&lt;br /&gt;  {&lt;br /&gt;   int i=0;&lt;br /&gt;   for(i=0;i&amp;lt;=arr.Length-1;i++)&lt;br /&gt;   { if(arr[i]==strSrc)&lt;br /&gt;     arr[i]=strReplace;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  string format (string str)&lt;br /&gt;  {&lt;br /&gt;   str = str.Replace(&amp;quot;\\&amp;quot;,&amp;quot;\\\\&amp;quot;);&lt;br /&gt;   str = str.Replace(&amp;quot;\&amp;quot;&amp;quot;,&amp;quot;\\\&amp;quot;&amp;quot;);&lt;br /&gt;   return str; &lt;br /&gt;  }&lt;br /&gt; string joinformat(string[] arr,string sep)&lt;br /&gt;  {&lt;br /&gt;   string strReturn= &amp;quot;&amp;quot; ;&lt;br /&gt;   foreach (string elt in arr)&lt;br /&gt;   { strReturn +=format( elt)+sep;}&lt;br /&gt;   &lt;br /&gt;   strReturn = strReturn.Substring( 0,strReturn.Length-sep.Length);&lt;br /&gt;    &lt;br /&gt;   return strReturn;&lt;br /&gt;  }&lt;br /&gt;        private void Form1_Load(object sender, System.EventArgs e)&lt;br /&gt;        {&lt;br /&gt;        //nothing special here &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private void button1_Click(object sender, System.EventArgs e)&lt;br /&gt;        {// here is starting the main part of the code:&lt;br /&gt;    //&lt;br /&gt;    //the CodeCompileUnit  is the  abstract code structure:&lt;br /&gt;&lt;br /&gt;            // Create a new CodeCompileUnit to contain the program graph&lt;br /&gt;            CodeCompileUnit CompileUnit = new CodeCompileUnit();&lt;br /&gt;            // Declare a new namespace called Samples.&lt;br /&gt;            CodeNamespace Samples = new CodeNamespace(&amp;quot;Samples&amp;quot;);&lt;br /&gt;            // Add the new namespace to the compile unit.&lt;br /&gt;            CompileUnit.Namespaces.Add( Samples );&lt;br /&gt;&lt;br /&gt;            // Add the new namespace import for the System namespace.&lt;br /&gt;            Samples.Imports.Add( new CodeNamespaceImport(&amp;quot;System&amp;quot;) );&lt;br /&gt;&lt;br /&gt;            // Declare a new type called Class1.&lt;br /&gt;            CodeTypeDeclaration Class1 = new CodeTypeDeclaration(&amp;quot;echo&amp;quot;);&lt;br /&gt;            // Add the new type to the namespace's type collection.&lt;br /&gt;            Samples.Types.Add(Class1);&lt;br /&gt;&lt;br /&gt;            //a variable declaration&lt;br /&gt;            CodeVariableDeclarationStatement Var = new&lt;br /&gt;   CodeVariableDeclarationStatement(&amp;quot;System.String&amp;quot;,&amp;quot;str1&amp;quot;);&lt;br /&gt;            // Declare a new code entry point method&lt;br /&gt;            CodeEntryPointMethod Start = new CodeEntryPointMethod();&lt;br /&gt;            // Create a new method invocation expression.&lt;br /&gt;            CodeMethodInvokeExpression cs1 =&lt;br /&gt;   new CodeMethodInvokeExpression(&lt;br /&gt;                // Call the System.Console.WriteLine method.&lt;br /&gt;                &lt;br /&gt;   new CodeTypeReferenceExpression(&amp;quot;System.Console&amp;quot;), &amp;quot;ReadLine&amp;quot;);&lt;br /&gt;            CodeAssignStatement as1 = new CodeAssignStatement(&lt;br /&gt;   new CodeVariableReferenceExpression(&amp;quot;str1&amp;quot;),cs1);&lt;br /&gt;&lt;br /&gt;            // Create a new method invocation expression.&lt;br /&gt;            CodeMethodInvokeExpression cs2 =&lt;br /&gt;   new CodeMethodInvokeExpression(&lt;br /&gt;                // Call the System.Console.WriteLine method.&lt;br /&gt;                new CodeTypeReferenceExpression(&amp;quot;System.Console&amp;quot;), &amp;quot;WriteLine&amp;quot;);&lt;br /&gt;            cs2.Parameters.Add(new CodeVariableReferenceExpression(Var.Name));&lt;br /&gt;&lt;br /&gt;            Start.Statements.Add(Var);&lt;br /&gt;            // Add the new method code statement.&lt;br /&gt;            Start.Statements.Add( as1);&lt;br /&gt;            // Add the new method code statement.&lt;br /&gt;            Start.Statements.Add(new CodeExpressionStatement(cs2));&lt;br /&gt;&lt;br /&gt;            // Add the code entry point method to the type's members collection&lt;br /&gt;            Class1.Members.Add( Start );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            System.IO.StringWriter Sw = new System.IO.StringWriter();&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;        Microsoft.CSharp.CSharpCodeProvider provider =&lt;br /&gt;        new CSharpCodeProvider();&lt;br /&gt;        System.CodeDom.Compiler.ICodeGenerator generator = provider.CreateGenerator(Sw);&lt;br /&gt;            CodeGeneratorOptions genOptions = new CodeGeneratorOptions();&lt;br /&gt;&lt;br /&gt;            // The code generator should insert blank lines &lt;br /&gt;            genOptions.BlankLinesBetweenMembers = true;&lt;br /&gt;&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                generator.GenerateCodeFromCompileUnit(CompileUnit,Sw,genOptions);&lt;br /&gt;            }&lt;br /&gt;            catch (Exception Exc)&lt;br /&gt;            {&lt;br /&gt;            System.Windows.Forms.MessageBox.Show (Exc.Message);&lt;br /&gt;            }&lt;br /&gt;            rt1.Text = Sw.ToString();&lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;             &lt;br /&gt;          private void button2_Click(object sender, System.EventArgs e)&lt;br /&gt;          {&lt;br /&gt;           Microsoft.CSharp.CSharpCodeProvider provider =&lt;br /&gt;        new CSharpCodeProvider();&lt;br /&gt;          ///&lt;br /&gt;//            Compilation &lt;br /&gt;            //instanciate csharp compiler&lt;br /&gt;            System.CodeDom.Compiler.ICodeCompiler MyCompiler = provider.CreateCompiler();&lt;br /&gt;            System.CodeDom.Compiler.CompilerParameters cp = new CompilerParameters();&lt;br /&gt;                        cp.GenerateExecutable = true;&lt;br /&gt;                        cp.CompilerOptions= &amp;quot; /target:exe&amp;quot;;&lt;br /&gt;                        cp.ReferencedAssemblies.AddRange( new string[]{&amp;quot;System.Windows.Forms.dll&amp;quot;,&amp;quot;System.dll&amp;quot;,&amp;quot;System.drawing.dll&amp;quot;,&amp;quot;&amp;quot;});&lt;br /&gt;            //where your exe will be  saved&lt;br /&gt;            cp.OutputAssembly = &amp;quot;c:\\echo.exe&amp;quot;;&lt;br /&gt;            // Invoke compilation.&lt;br /&gt;            CompilerResults cr = MyCompiler.CompileAssemblyFromSource ( cp,rt1.Text);&lt;br /&gt;        //&lt;br /&gt;        // Return the results of compilation.&lt;br /&gt;&lt;br /&gt;            //eventually load compilation output to the listbox (usefull to debug)&lt;br /&gt;            listBox1.DataSource=cr.Output;&lt;br /&gt;&lt;br /&gt;            //where is it? &lt;br /&gt;            MessageBox.Show ( cr.PathToAssembly );&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          private void bt_itself_Click(object sender, System.EventArgs e)&lt;br /&gt;          {&lt;br /&gt;   string[] arr=new string[]{&lt;br /&gt;&amp;quot;using System;&amp;quot;,&lt;br /&gt;&amp;quot;using System.Collections;&amp;quot;,&lt;br /&gt;&amp;quot;using System.ComponentModel;&amp;quot;,&lt;br /&gt;&amp;quot;using System.Windows.Forms;&amp;quot;,&lt;br /&gt;&amp;quot;using System.CodeDom;&amp;quot;,&lt;br /&gt;&amp;quot;using System.CodeDom.Compiler;&amp;quot;,&lt;br /&gt;&amp;quot;using Microsoft.CSharp;&amp;quot;,&lt;br /&gt;&amp;quot;using System.Collections.Specialized;&amp;quot;,&lt;br /&gt;&amp;quot;namespace WindowsApplication2&amp;quot;,&lt;br /&gt;&amp;quot;{&amp;quot;,&lt;br /&gt;&amp;quot;    /// Main form&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;    public class Form1 : System.Windows.Forms.Form&amp;quot;,&lt;br /&gt;&amp;quot;    {&amp;quot;,&lt;br /&gt;&amp;quot;  private System.Windows.Forms.Button button2;&amp;quot;,&lt;br /&gt;&amp;quot;  private System.Windows.Forms.Button button1;&amp;quot;,&lt;br /&gt;&amp;quot;  private System.Windows.Forms.Button bt_itself;&amp;quot;,&lt;br /&gt;&amp;quot;  private System.Windows.Forms.RichTextBox rt1;&amp;quot;,&lt;br /&gt;&amp;quot;  private System.Windows.Forms.ListBox listBox1;&amp;quot;,&lt;br /&gt;&amp;quot;        private System.ComponentModel.Container components = null;&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;        public Form1()&amp;quot;,&lt;br /&gt;&amp;quot;        {&amp;quot;,&lt;br /&gt;&amp;quot;            //&amp;quot;,&lt;br /&gt;&amp;quot;            // Requis pour la prise en charge du Concepteur Windows Forms&amp;quot;,&lt;br /&gt;&amp;quot;            //&amp;quot;,&lt;br /&gt;&amp;quot;            InitializeComponent();&amp;quot;,&lt;br /&gt;&amp;quot;        }&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;        /// Nettoyage des ressources utilisées.&amp;quot;,&lt;br /&gt;&amp;quot;        protected override void Dispose( bool disposing )&amp;quot;,&lt;br /&gt;&amp;quot;        {&amp;quot;,&lt;br /&gt;&amp;quot;            if( disposing )&amp;quot;,&lt;br /&gt;&amp;quot;            {&amp;quot;,&lt;br /&gt;&amp;quot;                if (components != null)&amp;quot;,&lt;br /&gt;&amp;quot;                {&amp;quot;,&lt;br /&gt;&amp;quot;                    components.Dispose();&amp;quot;,&lt;br /&gt;&amp;quot;                }&amp;quot;,&lt;br /&gt;&amp;quot;            }&amp;quot;,&lt;br /&gt;&amp;quot;            base.Dispose( disposing );&amp;quot;,&lt;br /&gt;&amp;quot;        }&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;        #region Code généré par le Concepteur Windows Form&amp;quot;,&lt;br /&gt;&amp;quot;        /// &amp;lt;summary&amp;gt;&amp;quot;,&lt;br /&gt;&amp;quot;        /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas&amp;quot;,&lt;br /&gt;&amp;quot;        /// le contenu de cette méthode avec l'éditeur de code.&amp;quot;,&lt;br /&gt;&amp;quot;        /// &amp;lt;/summary&amp;gt;&amp;quot;,&lt;br /&gt;&amp;quot;        private void InitializeComponent() {&amp;quot;,&lt;br /&gt;&amp;quot;   this.listBox1 = new System.Windows.Forms.ListBox();&amp;quot;,&lt;br /&gt;&amp;quot;   this.rt1 = new System.Windows.Forms.RichTextBox();&amp;quot;,&lt;br /&gt;&amp;quot;   this.bt_itself = new System.Windows.Forms.Button();&amp;quot;,&lt;br /&gt;&amp;quot;   this.button1 = new System.Windows.Forms.Button();&amp;quot;,&lt;br /&gt;&amp;quot;   this.button2 = new System.Windows.Forms.Button();&amp;quot;,&lt;br /&gt;&amp;quot;   this.SuspendLayout();&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   // listBox1&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   this.listBox1.Location = new System.Drawing.Point(24, 360);&amp;quot;,&lt;br /&gt;&amp;quot;   this.listBox1.Name = \&amp;quot;listBox1\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.listBox1.Size = new System.Drawing.Size(1016, 108);&amp;quot;,&lt;br /&gt;&amp;quot;   this.listBox1.TabIndex = 3;&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   // rt1&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   this.rt1.Location = new System.Drawing.Point(24, 16);&amp;quot;,&lt;br /&gt;&amp;quot;   this.rt1.Name = \&amp;quot;rt1\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.rt1.Size = new System.Drawing.Size(632, 328);&amp;quot;,&lt;br /&gt;&amp;quot;   this.rt1.TabIndex = 1;&amp;quot;,&lt;br /&gt;&amp;quot;   this.rt1.Text = \&amp;quot;richTextBox1\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   // bt_itself&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   this.bt_itself.Location = new System.Drawing.Point(696, 40);&amp;quot;,&lt;br /&gt;&amp;quot;   this.bt_itself.Name = \&amp;quot;bt_itself\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.bt_itself.Size = new System.Drawing.Size(72, 24);&amp;quot;,&lt;br /&gt;&amp;quot;   this.bt_itself.TabIndex = 0;&amp;quot;,&lt;br /&gt;&amp;quot;   this.bt_itself.Text = \&amp;quot;it self\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.bt_itself.Click += new System.EventHandler(this.bt_itself_Click);&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   // button1&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   this.button1.Location = new System.Drawing.Point(696, 8);&amp;quot;,&lt;br /&gt;&amp;quot;   this.button1.Name = \&amp;quot;button1\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.button1.Size = new System.Drawing.Size(72, 24);&amp;quot;,&lt;br /&gt;&amp;quot;   this.button1.TabIndex = 0;&amp;quot;,&lt;br /&gt;&amp;quot;   this.button1.Text = \&amp;quot;genere\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.button1.Click += new System.EventHandler(this.button1_Click);&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   // button2&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   this.button2.Location = new System.Drawing.Point(696, 72);&amp;quot;,&lt;br /&gt;&amp;quot;   this.button2.Name = \&amp;quot;button2\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.button2.Size = new System.Drawing.Size(72, 24);&amp;quot;,&lt;br /&gt;&amp;quot;   this.button2.TabIndex = 4;&amp;quot;,&lt;br /&gt;&amp;quot;   this.button2.Text = \&amp;quot;compile\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.button2.Click += new System.EventHandler(this.button2_Click);&amp;quot;,&lt;br /&gt;&amp;quot;   &amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   // Form1&amp;quot;,&lt;br /&gt;&amp;quot;   // &amp;quot;,&lt;br /&gt;&amp;quot;   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&amp;quot;,&lt;br /&gt;&amp;quot;   this.ClientSize = new System.Drawing.Size(1032, 526);&amp;quot;,&lt;br /&gt;&amp;quot;   this.Controls.Add(this.button2);&amp;quot;,&lt;br /&gt;&amp;quot;   this.Controls.Add(this.listBox1);&amp;quot;,&lt;br /&gt;&amp;quot;   this.Controls.Add(this.rt1);&amp;quot;,&lt;br /&gt;&amp;quot;   this.Controls.Add(this.button1);&amp;quot;,&lt;br /&gt;&amp;quot;   this.Controls.Add(this.bt_itself);&amp;quot;,&lt;br /&gt;&amp;quot;   this.Name = \&amp;quot;Form1\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.Text = \&amp;quot;Form1\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;   this.Load += new System.EventHandler(this.Form1_Load);&amp;quot;,&lt;br /&gt;&amp;quot;   this.ResumeLayout(false);&amp;quot;,&lt;br /&gt;&amp;quot;  }&amp;quot;,&lt;br /&gt;&amp;quot;        #endregion&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;        /// Point d'entrée principal de l'application.&amp;quot;,&lt;br /&gt;&amp;quot;        [STAThread]&amp;quot;,&lt;br /&gt;&amp;quot;        static void Main()&amp;quot;,&lt;br /&gt;&amp;quot;        {&amp;quot;,&lt;br /&gt;&amp;quot;            Application.Run(new Form1());&amp;quot;,&lt;br /&gt;&amp;quot;        }&amp;quot;,&lt;br /&gt;&amp;quot;// methode de base &amp;quot;,&lt;br /&gt;&amp;quot;  string join(string[] arr,string sep)&amp;quot;,&lt;br /&gt;&amp;quot;  {string strReturn=\&amp;quot;\&amp;quot; ;&amp;quot;,&lt;br /&gt;&amp;quot;   foreach (string elt in arr)&amp;quot;,&lt;br /&gt;&amp;quot;    strReturn += elt+sep;&amp;quot;,&lt;br /&gt;&amp;quot;   strReturn.Substring(0,strReturn.Length-sep.Length);&amp;quot;,&lt;br /&gt;&amp;quot;     &amp;quot;,&lt;br /&gt;&amp;quot;   return strReturn;&amp;quot;,&lt;br /&gt;&amp;quot;  }&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;  void seekandreplace(string[] arr,string strSrc,string strReplace)&amp;quot;,&lt;br /&gt;&amp;quot;  {&amp;quot;,&lt;br /&gt;&amp;quot;   int i=0;&amp;quot;,&lt;br /&gt;&amp;quot;   for(i=0;i&amp;lt;=arr.Length-1;i++)&amp;quot;,&lt;br /&gt;&amp;quot;   { if(arr[i]==strSrc)&amp;quot;,&lt;br /&gt;&amp;quot;     arr[i]=strReplace;&amp;quot;,&lt;br /&gt;&amp;quot;   }&amp;quot;,&lt;br /&gt;&amp;quot;  }&amp;quot;,&lt;br /&gt;&amp;quot;  string format (string str)&amp;quot;,&lt;br /&gt;&amp;quot;  {&amp;quot;,&lt;br /&gt;&amp;quot;   str = str.Replace(\&amp;quot;\\\\\&amp;quot;,\&amp;quot;\\\\\\\\\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;   str = str.Replace(\&amp;quot;\\\&amp;quot;\&amp;quot;,\&amp;quot;\\\\\\\&amp;quot;\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;   return str; &amp;quot;,&lt;br /&gt;&amp;quot;  }&amp;quot;,&lt;br /&gt;&amp;quot; string joinformat(string[] arr,string sep)&amp;quot;,&lt;br /&gt;&amp;quot;  {&amp;quot;,&lt;br /&gt;&amp;quot;   string strReturn= \&amp;quot;\&amp;quot; ;&amp;quot;,&lt;br /&gt;&amp;quot;   foreach (string elt in arr)&amp;quot;,&lt;br /&gt;&amp;quot;   { strReturn +=format( elt)+sep;}&amp;quot;,&lt;br /&gt;&amp;quot;   &amp;quot;,&lt;br /&gt;&amp;quot;   strReturn = strReturn.Substring( 0,strReturn.Length-sep.Length);&amp;quot;,&lt;br /&gt;&amp;quot;    &amp;quot;,&lt;br /&gt;&amp;quot;   return strReturn;&amp;quot;,&lt;br /&gt;&amp;quot;  }&amp;quot;,&lt;br /&gt;&amp;quot;        private void Form1_Load(object sender, System.EventArgs e)&amp;quot;,&lt;br /&gt;&amp;quot;        {&amp;quot;,&lt;br /&gt;&amp;quot;        //nothing special here &amp;quot;,&lt;br /&gt;&amp;quot;        }&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;        private void button1_Click(object sender, System.EventArgs e)&amp;quot;,&lt;br /&gt;&amp;quot;        {// here is starting the main part of the code:&amp;quot;,&lt;br /&gt;&amp;quot;    //&amp;quot;,&lt;br /&gt;&amp;quot;    //the CodeCompileUnit  is the  abstract code structure:&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            // Create a new CodeCompileUnit to contain the program graph&amp;quot;,&lt;br /&gt;&amp;quot;            CodeCompileUnit CompileUnit = new CodeCompileUnit();&amp;quot;,&lt;br /&gt;&amp;quot;            // Declare a new namespace called Samples.&amp;quot;,&lt;br /&gt;&amp;quot;            CodeNamespace Samples = new CodeNamespace(\&amp;quot;Samples\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;            // Add the new namespace to the compile unit.&amp;quot;,&lt;br /&gt;&amp;quot;            CompileUnit.Namespaces.Add( Samples );&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            // Add the new namespace import for the System namespace.&amp;quot;,&lt;br /&gt;&amp;quot;            Samples.Imports.Add( new CodeNamespaceImport(\&amp;quot;System\&amp;quot;) );&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            // Declare a new type called Class1.&amp;quot;,&lt;br /&gt;&amp;quot;            CodeTypeDeclaration Class1 = new CodeTypeDeclaration(\&amp;quot;echo\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;            // Add the new type to the namespace's type collection.&amp;quot;,&lt;br /&gt;&amp;quot;            Samples.Types.Add(Class1);&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            //a variable declaration&amp;quot;,&lt;br /&gt;&amp;quot;            CodeVariableDeclarationStatement Var = new&amp;quot;,&lt;br /&gt;&amp;quot;   CodeVariableDeclarationStatement(\&amp;quot;System.String\&amp;quot;,\&amp;quot;str1\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;            // Declare a new code entry point method&amp;quot;,&lt;br /&gt;&amp;quot;            CodeEntryPointMethod Start = new CodeEntryPointMethod();&amp;quot;,&lt;br /&gt;&amp;quot;            // Create a new method invocation expression.&amp;quot;,&lt;br /&gt;&amp;quot;            CodeMethodInvokeExpression cs1 =&amp;quot;,&lt;br /&gt;&amp;quot;   new CodeMethodInvokeExpression(&amp;quot;,&lt;br /&gt;&amp;quot;                // Call the System.Console.WriteLine method.&amp;quot;,&lt;br /&gt;&amp;quot;                &amp;quot;,&lt;br /&gt;&amp;quot;   new CodeTypeReferenceExpression(\&amp;quot;System.Console\&amp;quot;), \&amp;quot;ReadLine\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;            CodeAssignStatement as1 = new CodeAssignStatement(&amp;quot;,&lt;br /&gt;&amp;quot;   new CodeVariableReferenceExpression(\&amp;quot;str1\&amp;quot;),cs1);&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            // Create a new method invocation expression.&amp;quot;,&lt;br /&gt;&amp;quot;            CodeMethodInvokeExpression cs2 =&amp;quot;,&lt;br /&gt;&amp;quot;   new CodeMethodInvokeExpression(&amp;quot;,&lt;br /&gt;&amp;quot;                // Call the System.Console.WriteLine method.&amp;quot;,&lt;br /&gt;&amp;quot;                new CodeTypeReferenceExpression(\&amp;quot;System.Console\&amp;quot;), \&amp;quot;WriteLine\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;            cs2.Parameters.Add(new CodeVariableReferenceExpression(Var.Name));&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            Start.Statements.Add(Var);&amp;quot;,&lt;br /&gt;&amp;quot;            // Add the new method code statement.&amp;quot;,&lt;br /&gt;&amp;quot;            Start.Statements.Add( as1);&amp;quot;,&lt;br /&gt;&amp;quot;            // Add the new method code statement.&amp;quot;,&lt;br /&gt;&amp;quot;            Start.Statements.Add(new CodeExpressionStatement(cs2));&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            // Add the code entry point method to the type's members collection&amp;quot;,&lt;br /&gt;&amp;quot;            Class1.Members.Add( Start );&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            System.IO.StringWriter Sw = new System.IO.StringWriter();&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;        &amp;quot;,&lt;br /&gt;&amp;quot;        Microsoft.CSharp.CSharpCodeProvider provider =&amp;quot;,&lt;br /&gt;&amp;quot;        new CSharpCodeProvider();&amp;quot;,&lt;br /&gt;&amp;quot;        System.CodeDom.Compiler.ICodeGenerator generator = provider.CreateGenerator(Sw);&amp;quot;,&lt;br /&gt;&amp;quot;            CodeGeneratorOptions genOptions = new CodeGeneratorOptions();&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            // The code generator should insert blank lines &amp;quot;,&lt;br /&gt;&amp;quot;            genOptions.BlankLinesBetweenMembers = true;&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            try&amp;quot;,&lt;br /&gt;&amp;quot;            {&amp;quot;,&lt;br /&gt;&amp;quot;                generator.GenerateCodeFromCompileUnit(CompileUnit,Sw,genOptions);&amp;quot;,&lt;br /&gt;&amp;quot;            }&amp;quot;,&lt;br /&gt;&amp;quot;            catch (Exception Exc)&amp;quot;,&lt;br /&gt;&amp;quot;            {&amp;quot;,&lt;br /&gt;&amp;quot;            System.Windows.Forms.MessageBox.Show (Exc.Message);&amp;quot;,&lt;br /&gt;&amp;quot;            }&amp;quot;,&lt;br /&gt;&amp;quot;            rt1.Text = Sw.ToString();&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;          }&amp;quot;,&lt;br /&gt;&amp;quot;             &amp;quot;,&lt;br /&gt;&amp;quot;          private void button2_Click(object sender, System.EventArgs e)&amp;quot;,&lt;br /&gt;&amp;quot;          {&amp;quot;,&lt;br /&gt;&amp;quot;           Microsoft.CSharp.CSharpCodeProvider provider =&amp;quot;,&lt;br /&gt;&amp;quot;        new CSharpCodeProvider();&amp;quot;,&lt;br /&gt;&amp;quot;          ///&amp;quot;,&lt;br /&gt;&amp;quot;//            Compilation &amp;quot;,&lt;br /&gt;&amp;quot;            //instanciate csharp compiler&amp;quot;,&lt;br /&gt;&amp;quot;            System.CodeDom.Compiler.ICodeCompiler MyCompiler = provider.CreateCompiler();&amp;quot;,&lt;br /&gt;&amp;quot;            System.CodeDom.Compiler.CompilerParameters cp = new CompilerParameters();&amp;quot;,&lt;br /&gt;&amp;quot;                        cp.GenerateExecutable = true;&amp;quot;,&lt;br /&gt;&amp;quot;                        cp.CompilerOptions= \&amp;quot; /target:exe\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;                        cp.ReferencedAssemblies.AddRange( new string[]{\&amp;quot;System.Windows.Forms.dll\&amp;quot;,\&amp;quot;System.dll\&amp;quot;,\&amp;quot;System.drawing.dll\&amp;quot;,\&amp;quot;\&amp;quot;});&amp;quot;,&lt;br /&gt;&amp;quot;            //where your exe will be  saved&amp;quot;,&lt;br /&gt;&amp;quot;            cp.OutputAssembly = \&amp;quot;c:\\\\echo.exe\&amp;quot;;&amp;quot;,&lt;br /&gt;&amp;quot;            // Invoke compilation.&amp;quot;,&lt;br /&gt;&amp;quot;            CompilerResults cr = MyCompiler.CompileAssemblyFromSource ( cp,rt1.Text);&amp;quot;,&lt;br /&gt;&amp;quot;        //&amp;quot;,&lt;br /&gt;&amp;quot;        // Return the results of compilation.&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            //eventually load compilation output to the listbox (usefull to debug)&amp;quot;,&lt;br /&gt;&amp;quot;            listBox1.DataSource=cr.Output;&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;            //where is it? &amp;quot;,&lt;br /&gt;&amp;quot;            MessageBox.Show ( cr.PathToAssembly );&amp;quot;,&lt;br /&gt;&amp;quot;          }&amp;quot;,&lt;br /&gt;&amp;quot;&amp;quot;,&lt;br /&gt;&amp;quot;          private void bt_itself_Click(object sender, System.EventArgs e)&amp;quot;,&lt;br /&gt;&amp;quot;          {&amp;quot;,&lt;br /&gt;&amp;quot;   string[] arr=new string[]{&amp;quot;,&lt;br /&gt;&amp;quot;Les sanglots longs des violons de l'automne bercent mon coeur d'une langueur monotone&amp;quot;,&lt;br /&gt;&amp;quot;           };&amp;quot;,&lt;br /&gt;&amp;quot;           seekandreplace(arr,\&amp;quot;Les sanglots longs des violons de l'automne bercent mon coeur d'une langueur monotone\&amp;quot;,\&amp;quot;\\\&amp;quot;\&amp;quot;+joinformat(arr,\&amp;quot;\\\&amp;quot;,\\n\\\&amp;quot;\&amp;quot;)+\&amp;quot;\\\&amp;quot;\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;   this.rt1.Text = join(arr,\&amp;quot;\\n\&amp;quot;);&amp;quot;,&lt;br /&gt;&amp;quot;           }&amp;quot;,&lt;br /&gt;&amp;quot;    }&amp;quot;,&lt;br /&gt;&amp;quot;}&amp;quot;&lt;br /&gt;           };&lt;br /&gt;           seekandreplace(arr,&amp;quot;Les sanglots longs des violons de l'automne bercent mon coeur d'une langueur monotone&amp;quot;,&amp;quot;\&amp;quot;&amp;quot;+joinformat(arr,&amp;quot;\&amp;quot;,\n\&amp;quot;&amp;quot;)+&amp;quot;\&amp;quot;&amp;quot;);&lt;br /&gt;   this.rt1.Text = join(arr,&amp;quot;\n&amp;quot;);&lt;br /&gt;           }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111963156641193542?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111963156641193542/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111963156641193542&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111963156641193542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111963156641193542'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/06/self-description.html' title='self description'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111901103443374866</id><published>2005-06-17T05:21:00.000-07:00</published><updated>2007-03-16T14:41:56.263-07:00</updated><title type='text'>A web crawler(regular expressions and  httprequest)</title><content type='html'>Hello  everybody, i'm back to the blog!&lt;br /&gt;&lt;br /&gt;Today I'd like to demonstrate  two powerfull features of the .net Framework: the httpWebrequest/httWebResponse and the  RegEx object.  I will  then propose an implementation  of a  mini Web Crawler.&lt;br /&gt;&lt;br /&gt;httpWebrequest and httWebResponse are both object  of the System.Net  namespace. &lt;br /&gt;With  this objects, retrieving a text stream from a URI  is as easy as this:&lt;br /&gt;&lt;br /&gt;&lt;font  face = "courier"&gt;&lt;b&gt;&lt;br /&gt;// Creates an HttpWebRequest with the specified URL. &lt;br /&gt;HttpWebRequest myHttpWebRequest;&lt;br /&gt;  &lt;br /&gt;myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL); &lt;br /&gt;      &lt;br /&gt;// Sends the HttpWebRequest and waits for the response.            &lt;br /&gt;HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); &lt;br /&gt;// Gets the stream associated with the response.&lt;br /&gt;Stream receiveStream = myHttpWebResponse.GetResponseStream();&lt;br /&gt;Encoding encode = System.Text.Encoding.GetEncoding("utf-8");&lt;br /&gt;// Pipes the stream to a higher level stream reader with the required encoding format. &lt;br /&gt;StreamReader readStream = new StreamReader( receiveStream, encode );&lt;br /&gt;Char[] read = new Char[256];&lt;br /&gt;// Reads 256 characters at a time.    &lt;br /&gt;int count = readStream.Read( read, 0, 256 );&lt;br /&gt;      &lt;br /&gt;while (count &gt; 0) &lt;br /&gt;{&lt;br /&gt; // Dumps the 256 characters on a string .&lt;br /&gt; String str = new String(read,0, count);&lt;br /&gt; strRes  +=str;&lt;br /&gt; count = readStream.Read(read, 0, 256);&lt;br /&gt;}&lt;br /&gt;// Releases the resources of the response.&lt;br /&gt;myHttpWebResponse.Close();&lt;br /&gt;// Releases the resources of the Stream.&lt;br /&gt;readStream.Close(); &lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;The regEx object is the .net implementation for regular expressions. If you don't know what it is just remember it's the best way to perform text analysis. &lt;br /&gt;For instance here is a function which retrieves in an array the "href"s in a web page. &lt;br /&gt;&lt;br /&gt;&lt;font  face = "courier"&gt;&lt;b&gt;&lt;br /&gt;  private  string [] extractURIS(string strHTML)&lt;br /&gt;  {&lt;br /&gt;   Match m;&lt;br /&gt;&lt;br /&gt;   String[] results = new String[101];&lt;br /&gt; &lt;br /&gt;    &lt;br /&gt;   // Create a new Regex object and define the regular expression.&lt;br /&gt;   Regex r = new Regex(&lt;font color="blue"&gt;"href\\s*=\\s*(?:\"(?'1'[^\"]*)\"|(?'1'\\S+)).*&gt;"&lt;/font&gt;,&lt;br /&gt;   RegexOptions.IgnoreCase|RegexOptions.Compiled);&lt;br /&gt;&lt;br /&gt;   // Use the Matches method to find all matches in the input string.&lt;br /&gt;   // Loop through the match collection to retrieve all &lt;br /&gt;   // matches.&lt;br /&gt;   int i=0;&lt;br /&gt;   m = r.Match(strHTML);&lt;br /&gt;    &lt;br /&gt;   for (i=0; (m.Success &amp;&amp; i&amp;lt;100); m = m.NextMatch()) &lt;br /&gt;   {i++;&lt;br /&gt;&lt;br /&gt;    // Add the match string to the string array.   &lt;br /&gt;    results[i] = m.Groups[1].ToString() ;&lt;br /&gt; &lt;br /&gt;   }&lt;br /&gt;  return results;&lt;br /&gt;  }&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;OK,  have a great  breath and  look at this&lt;br /&gt;"href\\s*=\\s*(?:\"(?'1'[^\"]*)\"|(?'1'\\S+)).*&amp;gt;"&lt;br /&gt;let's  decrypt this  regular expression . &lt;br /&gt;"href"   just mean that the patern is preceded by the word "href"&lt;br /&gt;\\s stands for  "any  space character" &lt;br /&gt;\\s*  stands for "a 0 or n space character"&lt;br /&gt;so  the first part of the regEx  :"href\\s*=\\s*" mean  that the pattern we are looking for  begins by "href" then  spaces,  then  the "=" character and  then spaces. &lt;br /&gt;&lt;br /&gt;[^\"]  means "everything but a double quote  character" (the \ is here to say " isnt a special character of the RegEx)&lt;br /&gt;so [^\"]*  is  a succession of 0 or n  character whithout any double quote&lt;br /&gt;&lt;br /&gt;(?'1'......) means  that whe give the name '1'  to the .... expression &lt;br /&gt;Here we use it  two times    in the subexpression:&lt;br /&gt;\"(?'1'[^\"]*)\"|(?'1'\\S+) &lt;br /&gt;knowing that "|" is a logicall OR, you can guess that '1' is  either &lt;br /&gt;a succession of "without double quote" between  two  double quotes  or  "a succession of at least one non spaces characters"(\\S+)&lt;br /&gt;&lt;br /&gt;(?:....)  just propagate the subexpression  to the  top level .&lt;br /&gt; &lt;br /&gt;a dot (.) means "any character"&lt;br /&gt;so:&lt;br /&gt;.*&amp;gt; means that our  regEx  ends with a succession of  any character an then a "&amp;gt;"&lt;br /&gt;&lt;br /&gt;wow... &lt;br /&gt;for further info have a look to : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconregularexpressionslanguageelements.asp&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So  lets use it in our little  web crawler. &lt;br /&gt;&lt;br /&gt;To compile  the following  , save it with a ".cs" extension and use the csc.exe  of your  framework installation, for instance use the following:&lt;br /&gt;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe /target:winexe /recurse:*.*&lt;br /&gt;int the cs directory. &lt;br /&gt;&lt;br /&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Windows.Forms;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Net;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;using System.Collections.Specialized;&lt;br /&gt;&lt;br /&gt;namespace webrequest&lt;br /&gt;{&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Description résumée de Form1.&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;public class WebCrawler : System.Windows.Forms.Form&lt;br /&gt;{&lt;br /&gt;private System.Windows.Forms.Button btLoad;&lt;br /&gt;private System.Windows.Forms.TextBox tbURI;&lt;br /&gt;private System.Windows.Forms.RichTextBox rtbHTML;&lt;br /&gt;private System.Windows.Forms.RichTextBox rtbLOg;&lt;br /&gt;&lt;br /&gt;private string MainString;&lt;br /&gt;private StringDictionary dicURL;&lt;br /&gt;private System.Windows.Forms.Label label1;&lt;br /&gt;private System.Windows.Forms.Label label2;&lt;br /&gt;private System.Windows.Forms.TextBox tbiProf;&lt;br /&gt;private System.Windows.Forms.TextBox tbMax;&lt;br /&gt;private System.Windows.Forms.Label label3; &lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Variable nécessaire au concepteur.&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;private System.ComponentModel.Container components = null;&lt;br /&gt;&lt;br /&gt;public WebCrawler()&lt;br /&gt;{&lt;br /&gt; dicURL = new StringDictionary();&lt;br /&gt; //&lt;br /&gt; // Requis pour la prise en charge du Concepteur Windows Forms&lt;br /&gt; //&lt;br /&gt; InitializeComponent();&lt;br /&gt;&lt;br /&gt; //&lt;br /&gt; // TODO : ajoutez le code du constructeur après l'appel à InitializeComponent&lt;br /&gt; //&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Nettoyage des ressources utilisées.&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;protected override void Dispose( bool disposing )&lt;br /&gt;{&lt;br /&gt; if( disposing )&lt;br /&gt; {&lt;br /&gt;  if (components != null) &lt;br /&gt;  {&lt;br /&gt;   components.Dispose();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; base.Dispose( disposing );&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#region Code généré par le Concepteur Windows Form&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas&lt;br /&gt;/// le contenu de cette méthode avec l'éditeur de code.&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;private void InitializeComponent()&lt;br /&gt;{&lt;br /&gt; this.btLoad = new System.Windows.Forms.Button();&lt;br /&gt; this.tbURI = new System.Windows.Forms.TextBox();&lt;br /&gt; this.rtbHTML = new System.Windows.Forms.RichTextBox();&lt;br /&gt; this.rtbLOg = new System.Windows.Forms.RichTextBox();&lt;br /&gt; this.tbiProf = new System.Windows.Forms.TextBox();&lt;br /&gt; this.label1 = new System.Windows.Forms.Label();&lt;br /&gt; this.label2 = new System.Windows.Forms.Label();&lt;br /&gt; this.tbMax = new System.Windows.Forms.TextBox();&lt;br /&gt; this.label3 = new System.Windows.Forms.Label();&lt;br /&gt; this.SuspendLayout();&lt;br /&gt; // &lt;br /&gt; // btLoad&lt;br /&gt; // &lt;br /&gt; this.btLoad.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) &lt;br /&gt;  | System.Windows.Forms.AnchorStyles.Left) &lt;br /&gt;  | System.Windows.Forms.AnchorStyles.Right)));&lt;br /&gt; this.btLoad.Location = new System.Drawing.Point(16, 112);&lt;br /&gt; this.btLoad.Name = "btLoad";&lt;br /&gt; this.btLoad.Size = new System.Drawing.Size(272, 120);&lt;br /&gt; this.btLoad.TabIndex = 0;&lt;br /&gt; this.btLoad.Text = "Crawl!";&lt;br /&gt; this.btLoad.Click += new System.EventHandler(this.btLoad_Click);&lt;br /&gt; // &lt;br /&gt; // tbURI&lt;br /&gt; // &lt;br /&gt; this.tbURI.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) &lt;br /&gt;  | System.Windows.Forms.AnchorStyles.Right)));&lt;br /&gt; this.tbURI.Location = new System.Drawing.Point(120, 16);&lt;br /&gt; this.tbURI.Name = "tbURI";&lt;br /&gt; this.tbURI.Size = new System.Drawing.Size(712, 20);&lt;br /&gt; this.tbURI.TabIndex = 1;&lt;br /&gt; this.tbURI.Text = "http://oraclevsmicrosoft.blogspot.com";&lt;br /&gt; // &lt;br /&gt; // rtbHTML&lt;br /&gt; // &lt;br /&gt; this.rtbHTML.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) &lt;br /&gt;  | System.Windows.Forms.AnchorStyles.Right)));&lt;br /&gt; this.rtbHTML.Location = new System.Drawing.Point(8, 248);&lt;br /&gt; this.rtbHTML.Name = "rtbHTML";&lt;br /&gt; this.rtbHTML.Size = new System.Drawing.Size(832, 136);&lt;br /&gt; this.rtbHTML.TabIndex = 2;&lt;br /&gt; this.rtbHTML.Text = "";&lt;br /&gt; // &lt;br /&gt; // rtbLOg&lt;br /&gt; // &lt;br /&gt; this.rtbLOg.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) &lt;br /&gt;  | System.Windows.Forms.AnchorStyles.Right)));&lt;br /&gt; this.rtbLOg.Location = new System.Drawing.Point(297, 40);&lt;br /&gt; this.rtbLOg.Name = "rtbLOg";&lt;br /&gt; this.rtbLOg.Size = new System.Drawing.Size(536, 200);&lt;br /&gt; this.rtbLOg.TabIndex = 3;&lt;br /&gt; this.rtbLOg.Text = "";&lt;br /&gt; this.rtbLOg.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.rtbLOg_LinkClicked);&lt;br /&gt; // &lt;br /&gt; // tbiProf&lt;br /&gt; // &lt;br /&gt; this.tbiProf.Location = new System.Drawing.Point(120, 48);&lt;br /&gt; this.tbiProf.Name = "tbiProf";&lt;br /&gt; this.tbiProf.Size = new System.Drawing.Size(48, 20);&lt;br /&gt; this.tbiProf.TabIndex = 4;&lt;br /&gt; this.tbiProf.Text = "5";&lt;br /&gt; // &lt;br /&gt; // label1&lt;br /&gt; // &lt;br /&gt; this.label1.Location = new System.Drawing.Point(8, 16);&lt;br /&gt; this.label1.Name = "label1";&lt;br /&gt; this.label1.Size = new System.Drawing.Size(88, 16);&lt;br /&gt; this.label1.TabIndex = 5;&lt;br /&gt; this.label1.Text = "Starting URI";&lt;br /&gt; // &lt;br /&gt; // label2&lt;br /&gt; // &lt;br /&gt; this.label2.Location = new System.Drawing.Point(8, 48);&lt;br /&gt; this.label2.Name = "label2";&lt;br /&gt; this.label2.Size = new System.Drawing.Size(88, 16);&lt;br /&gt; this.label2.TabIndex = 6;&lt;br /&gt; this.label2.Text = "Max depht";&lt;br /&gt; // &lt;br /&gt; // tbMax&lt;br /&gt; // &lt;br /&gt; this.tbMax.Location = new System.Drawing.Point(120, 80);&lt;br /&gt; this.tbMax.Name = "tbMax";&lt;br /&gt; this.tbMax.Size = new System.Drawing.Size(104, 20);&lt;br /&gt; this.tbMax.TabIndex = 4;&lt;br /&gt; this.tbMax.Text = "1000";&lt;br /&gt; // &lt;br /&gt; // label3&lt;br /&gt; // &lt;br /&gt; this.label3.Location = new System.Drawing.Point(8, 88);&lt;br /&gt; this.label3.Name = "label3";&lt;br /&gt; this.label3.Size = new System.Drawing.Size(112, 16);&lt;br /&gt; this.label3.TabIndex = 6;&lt;br /&gt; this.label3.Text = "Max number of links";&lt;br /&gt; // &lt;br /&gt; // WebCrawler&lt;br /&gt; // &lt;br /&gt; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt; this.ClientSize = new System.Drawing.Size(848, 398);&lt;br /&gt; this.Controls.Add(this.label2);&lt;br /&gt; this.Controls.Add(this.label1);&lt;br /&gt; this.Controls.Add(this.tbiProf);&lt;br /&gt; this.Controls.Add(this.rtbLOg);&lt;br /&gt; this.Controls.Add(this.rtbHTML);&lt;br /&gt; this.Controls.Add(this.tbURI);&lt;br /&gt; this.Controls.Add(this.btLoad);&lt;br /&gt; this.Controls.Add(this.tbMax);&lt;br /&gt; this.Controls.Add(this.label3);&lt;br /&gt; this.MinimumSize = new System.Drawing.Size(856, 432);&lt;br /&gt; this.Name = "WebCrawler";&lt;br /&gt; this.Text = "Form1";&lt;br /&gt; this.ResumeLayout(false);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Point d'entrée principal de l'application.&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;[STAThread]&lt;br /&gt;static void Main() &lt;br /&gt;{&lt;br /&gt; Application.Run(new WebCrawler());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// ne garde que le body  du document et remplace toutes les balises par un espace simple&lt;br /&gt;// enfin  decode le html pour remplacer les énbsp; et autres&lt;br /&gt;private  string deleteTagg(string strHTML)&lt;br /&gt;{&lt;br /&gt; Match m;&lt;br /&gt; string strRes ="";&lt;br /&gt; Regex r = new Regex ("&amp;lt;body.*&amp;gt;(.|\\n)*&amp;lt;/body&amp;gt;",&lt;br /&gt;  RegexOptions.IgnoreCase);&lt;br /&gt; m = r.Match(strHTML); &lt;br /&gt; if (m.Success ) &lt;br /&gt; {&lt;br /&gt;   strRes  = m.Value;&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; r = null;&lt;br /&gt; r = new Regex ("&amp;lt;(.|\\n)*?&amp;gt;",&lt;br /&gt;  RegexOptions.IgnoreCase);&lt;br /&gt; strRes = r.Replace(strRes," ");&lt;br /&gt;&lt;br /&gt; strRes  =HttpUtility.HtmlDecode(strRes);&lt;br /&gt;&lt;br /&gt; return strRes ;&lt;br /&gt;}&lt;br /&gt;private  string [] extractURIS(string strHTML)&lt;br /&gt;{&lt;br /&gt; Match m;&lt;br /&gt;&lt;br /&gt; String[] results = new String[101];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; // Create a new Regex object and define the regular expression.&lt;br /&gt; Regex r = new Regex ("href\\s*=\\s*(?:\"(?'1'[^\"]*)\"|(?'1'\\S+)).*&amp;gt;",&lt;br /&gt; RegexOptions.IgnoreCase|RegexOptions.Compiled);&lt;br /&gt;&lt;br /&gt; // Use the Matches method to find all matches in the input string.&lt;br /&gt; // Loop through the match collection to retrieve all &lt;br /&gt; // matches.&lt;br /&gt; int i=0;&lt;br /&gt; m = r.Match(strHTML);&lt;br /&gt;  &lt;br /&gt; for (i=0; (m.Success &amp;&amp; i&amp;lt;100); m = m.NextMatch()) &lt;br /&gt; {i++;&lt;br /&gt;&lt;br /&gt;  // Add the match string to the string array.   &lt;br /&gt;  results[i] = m.Groups[1].ToString() ;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;return results;&lt;br /&gt;}&lt;br /&gt;private string  loadUrl(string strURL)&lt;br /&gt;{&lt;br /&gt; string strRes="" ; &lt;br /&gt; try &lt;br /&gt; {&lt;br /&gt;  // Creates an HttpWebRequest with the specified URL. &lt;br /&gt;  HttpWebRequest myHttpWebRequest;&lt;br /&gt;  &lt;br /&gt;  myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL); &lt;br /&gt;    &lt;br /&gt;  // Sends the HttpWebRequest and waits for the response.            &lt;br /&gt;  HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); &lt;br /&gt;  // Gets the stream associated with the response.&lt;br /&gt;  Stream receiveStream = myHttpWebResponse.GetResponseStream();&lt;br /&gt;  Encoding encode = System.Text.Encoding.GetEncoding("utf-8");&lt;br /&gt;  // Pipes the stream to a higher level stream reader with the required encoding format. &lt;br /&gt;  StreamReader readStream = new StreamReader( receiveStream, encode );&lt;br /&gt;  Char[] read = new Char[256];&lt;br /&gt;  // Reads 256 characters at a time.    &lt;br /&gt;  int count = readStream.Read( read, 0, 256 );&lt;br /&gt;    &lt;br /&gt;  while (count &amp;gt; 0) &lt;br /&gt;  {&lt;br /&gt;   // Dumps the 256 characters on a string .&lt;br /&gt;   String str = new String(read,0, count);&lt;br /&gt;   strRes  +=str;&lt;br /&gt;   count = readStream.Read(read, 0, 256);&lt;br /&gt;  }&lt;br /&gt;  // Releases the resources of the response.&lt;br /&gt;  myHttpWebResponse.Close();&lt;br /&gt;  // Releases the resources of the Stream.&lt;br /&gt;  readStream.Close();&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; catch(Exception exp)&lt;br /&gt; {&lt;br /&gt;  rtbLOg.AppendText("error at URI : "+ strURL +"\n");&lt;br /&gt;  strRes ="";&lt;br /&gt; }&lt;br /&gt; return strRes;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void btLoad_Click(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt; recure(tbURI.Text,Convert.ToInt16(tbiProf.Text));&lt;br /&gt; rtbLOg.AppendText(dicURL.Count.ToString ());&lt;br /&gt;}&lt;br /&gt;private void recure(string strURL,int  ilevel)&lt;br /&gt;{&lt;br /&gt; MainString="";&lt;br /&gt; Match m;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; if ((ilevel)&amp;gt;0 )&lt;br /&gt; {&lt;br /&gt;  &lt;br /&gt;  MainString = loadUrl(strURL);&lt;br /&gt; &lt;br /&gt;   if (dicURL.Count&amp;lt;Convert.ToInt32(tbMax.Text))&lt;br /&gt;   {&lt;br /&gt;    // récuperation des URLS&lt;br /&gt;    string []strArUris= extractURIS(MainString);&lt;br /&gt;    for (int i=0; i&amp;lt;strArUris.Length&amp;&amp;dicURL.Count&amp;lt;Convert.ToInt32(tbMax.Text);i++)&lt;br /&gt;    {&lt;br /&gt;     if (strArUris[i]!=null)&lt;br /&gt;     {&lt;br /&gt;      // check that the  URi begins with  a http&lt;br /&gt;      Regex r = new Regex ("http://.+",&lt;br /&gt;       RegexOptions.IgnoreCase);&lt;br /&gt;      m = r.Match(strArUris[i]); &lt;br /&gt;      &lt;br /&gt;      if (!dicURL.ContainsKey(strArUris[i])&amp;&amp; m.Success )&lt;br /&gt;      {&lt;br /&gt;       dicURL.Add(strArUris[i],"1");&lt;br /&gt;       recure(strArUris[i],ilevel-1);&lt;br /&gt;       rtbLOg.AppendText(strArUris[i]+"  " +ilevel+"\n");&lt;br /&gt;      &lt;br /&gt;      }&lt;br /&gt;      else&lt;br /&gt;       dicURL[strArUris[i]]=Convert.ToString(Convert.ToInt32(dicURL[strArUris[i]])+1);&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   //here could be a text flow extraction &lt;br /&gt;   //  rtbHTML.Text  =deleteTagg(rtbHTML.Text);&lt;br /&gt;   //rtbHTML.Text  =deleteTagg("&amp;lt;/body&amp;gt;");&lt;br /&gt; }&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void rtbLOg_LinkClicked(object sender, System.Windows.Forms.LinkClickedEventArgs e)&lt;br /&gt;{&lt;br /&gt; //Launch  in ie &lt;br /&gt; System.Diagnostics.Process.Start(e.LinkText);&lt;br /&gt; rtbHTML.Text= deleteTagg(loadUrl(e.LinkText));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Thats all folks! Hope this helps, comments are welcome. &lt;br /&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111901103443374866?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111901103443374866/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111901103443374866&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111901103443374866'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111901103443374866'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/06/web-crawlerregular-expressions-and.html' title='A web crawler(regular expressions and  httprequest)'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111467499929986766</id><published>2005-04-28T00:55:00.000-07:00</published><updated>2005-04-28T00:56:39.300-07:00</updated><title type='text'>link</title><content type='html'>just a link  today:&lt;br /&gt;&lt;a href="http://www.dbforumz.com" target="_blank" title="Database Forums" alt="Database Forums"&gt;Database Forums&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111467499929986766?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111467499929986766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111467499929986766&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111467499929986766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111467499929986766'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/04/link.html' title='link'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111391711632447563</id><published>2005-04-19T06:23:00.000-07:00</published><updated>2007-03-03T02:26:00.373-08:00</updated><title type='text'>call an Oracle stored proc  with oledb .net</title><content type='html'>Thanks to Emilio who ask the question  on  microsoft.public.dotnet.framework.adonet  newsgroup. &lt;br /&gt;&lt;br /&gt;here is a  syntaxe I've just test  :&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;style type="text/css"&gt; .csharpcode { font-size: 10pt; color: black; font-family: Courier New , Courier, Monospace; background-color: #ffffff; /*white-space: pre;*/ }&lt;br /&gt; .csharpcode pre { margin: 0px; }&lt;br /&gt; .rem { color: #008000; }&lt;br /&gt; .kwrd { color: #0000ff; }&lt;br /&gt; .str { color: #006080; }&lt;br /&gt; .op { color: #0000c0; }&lt;br /&gt; .preproc { color: #cc6633; }&lt;br /&gt; .asp { background-color: #ffff00; }&lt;br /&gt; .html { color: #800000; }&lt;br /&gt; .attr { color: #ff0000; }&lt;br /&gt; .alt { background-color: #f4f4f4; width: 100%; margin: 0px; }&lt;br /&gt; .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.cmdInsertLib.CommandText = &lt;span class="str"&gt;"MyStoredProc"&lt;/span&gt;;&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.cmdInsertLib.CommandType = System.Data.CommandType.StoredProcedure;&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.cmdInsertLib.Parameters.Add(&lt;span class="kwrd"&gt;&lt;br /&gt;  new&lt;/span&gt; System.Data.OleDb.OleDbParameter(&lt;span class="str"&gt;"P1"&lt;/span&gt;,&lt;br /&gt;  System.Data.OleDb.OleDbType.VarWChar, 100));&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.cmdInsertLib.Parameters.Add(&lt;span class="kwrd"&gt;&lt;br /&gt;  new&lt;/span&gt; System.Data.OleDb.OleDbParameter(&lt;span class="str"&gt;"P2"&lt;/span&gt;, &lt;br /&gt;  System.Data.OleDb.OleDbType.VarWChar, 100));&lt;br /&gt;cmdInsertLib.Parameters[0].Value = textBox1.Text.ToString();&lt;br /&gt;cmdInsertLib.Parameters[1].Value = textBox2.Text.ToString();&lt;br /&gt;cmdInsertLib.ExecuteNonQuery();&lt;/pre&gt;&lt;br /&gt;that's all folks &lt;br /&gt;&lt;br /&gt;hope this helps&lt;br /&gt;&lt;br /&gt;comments are welcome&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111391711632447563?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111391711632447563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111391711632447563&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111391711632447563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111391711632447563'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/04/call-oracle-stored-proc-with-oledb-net.html' title='call an Oracle stored proc  with oledb .net'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111289557316737504</id><published>2005-04-07T10:10:00.000-07:00</published><updated>2007-02-20T21:03:41.056-08:00</updated><title type='text'>Updating  two lines  with one data adapter.</title><content type='html'>&lt;div class="Section1"&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Datatables and dataAdapter are designed to manipulate one database table at a time. The idea is that dataTable is like an asynchronous part of the database. So, when you make a change on one row of the dataTable you are suppose to change one and only one row in the database's table when synchronizing. Of course, sometimes it is not what you would like to do. &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Today I would like to demonstrate how to update multiple rows in an Oracle table without any Stored Procedure but with oracle specific SQL. &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;A few days ago, I worked on a little multi-language tool. In a financial application, some labels where needed to be translate from French to English.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Therefore, I decided to make a little tool for the users in order to administrate their label’s translations. &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;There were three tables:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;REF_LABEL:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;IDT_LABEL PK&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;COM_LABEL unique &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;....&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;REF_LANGUAGE :&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;IDT_LNG PK&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;COM_LNG&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;REF_TRANSLATION:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;IDT_LABEL FK PK&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;IDT_LNG PK&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;COM_TRANS &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;The requirement was to "provide&lt;br /&gt;a grid with COM_LABEL, the French translation and the English one for each&lt;br /&gt;label. The French and English translation available for modification"&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;First, I defined the main query: &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"    style="font-family:'Courier New';font-size:10;color:blue;"&gt;string&lt;/span&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt; strSelect= &lt;span style="color:blue;"&gt;" select COM_LABEL, FR.COM_TRANS, EN.COM_TRANS from&lt;br /&gt;REF_TRANSLATION EN, REF_TRANSLATION FR, REF_LABEL L"&lt;/span&gt;&lt;br /&gt;+&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;span style="color:blue;"&gt;" where L.IDT_LABEL = EN.IDT_LABEL "&lt;/span&gt; +&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;span style="color:blue;"&gt;" and L.IDT_LABEL = FR.IDT_LABEL"&lt;/span&gt; +&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;span style="color:blue;"&gt;" and EN.IDT_LNG = 2 -- the English id "&lt;/span&gt; +&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;span style="color:blue;"&gt;" and FR.IDT_LNG = 1 -- the French one "&lt;/span&gt; ;&lt;span style="color:blue;"&gt;"&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Then, I set the preceding as the CommandText property of an oledbCommand: &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;System.Data.OleDb.OleDbCommand cmdS = &lt;span style="color:blue;"&gt;new&lt;/span&gt; System.Data.OleDb.OleDbCommand();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;cmdS.CommandText =&lt;br /&gt;strSelect ;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;cmdS.Connection = MyValidConnection;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Next step was the update SQL command,&lt;br /&gt;pay attention to the decode function:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;System.Data.OleDb.OleDbCommand cmdU = &lt;span style="color:blue;"&gt;new&lt;/span&gt; System.Data.OleDb.OleDbCommand();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;cmdU.CommandText = &lt;span style="color:blue;"&gt;"update ref_translation set com_trans = decode&lt;br /&gt;(idt_lng,1, ?,2,?) where idt_label = ?"&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;cmdU.Connection =&lt;br /&gt;MyValidConnection;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;"?" are parameters, that I&lt;br /&gt;defined by:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;cmdU.Parameters.Add(&lt;span style="color:blue;"&gt;new&lt;/span&gt; System.Data.OleDb.OleDbParameter(&lt;span style="color:blue;"&gt;"COM_TRANS_FR"&lt;/span&gt;,&lt;br /&gt;System.Data.OleDb.OleDbType.Variant, 80, &lt;span style="color:blue;"&gt;"LBL_VAL_FR"&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;cmdU.Parameters.Add(&lt;span style="color:blue;"&gt;new&lt;/span&gt; System.Data.OleDb.OleDbParameter(&lt;span style="color:blue;"&gt;"COM_TRANS_EN"&lt;/span&gt;,&lt;br /&gt;System.Data.OleDb.OleDbType.Variant, 80, &lt;span style="color:blue;"&gt;"LBL_VAL_EN"&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;cmdU.Parameters.Add(&lt;span style="color:blue;"&gt;new&lt;/span&gt; System.Data.OleDb.OleDbParameter(&lt;span style="color:blue;"&gt;"IDT_LABEL"&lt;/span&gt;,&lt;br /&gt;System.Data.OleDb.OleDbType.Decimal, 0, System.Data.ParameterDirection.Input, &lt;span style="color:blue;"&gt;false&lt;/span&gt;, ((System.Byte)(4)), ((System.Byte)(0)), &lt;span style="color:blue;"&gt;"IDT_LABEL"&lt;/span&gt;,&lt;br /&gt;System.Data.DataRowVersion.Original, &lt;span style="color:blue;"&gt;null&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;The "decode" function is Oracle specific. If you do not know this function, let us says that it is something like a C/C++/C# switch clause or a VB select case, but as a function. It takes&lt;br /&gt;at least three arguments and return the third argument if the first is equal to the second, the fifth if the first is equal to the fourth etc... For further&lt;br /&gt;info : &lt;a href="http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96540/functions33a.htm#1017439"&gt;http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96540/functions33a.htm#1017439&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Then, I defined my dataAdapter by adding the following:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;System.Data.OleDb.OleDbDataAdapter daLib = &lt;span style="color:blue;"&gt;new &lt;/span&gt;System.Data.OleDb.OleDbDataAdapter();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;daLib.SelectCommand = cmdS;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;daLib.UpdateCommand = cmdU;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:'Courier New';font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Hoops! Two pages, that is too long for one post. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;That’s all folks!&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span lang="EN-US"   style="font-family:Arial;font-size:10;"&gt;Comments are welcome!&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111289557316737504?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111289557316737504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111289557316737504&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111289557316737504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111289557316737504'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/04/updating-two-lines-with-one-data.html' title='Updating  two lines  with one data adapter.'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111236712457878826</id><published>2005-04-01T06:38:00.000-08:00</published><updated>2005-04-01T06:52:04.583-08:00</updated><title type='text'>oracle functions</title><content type='html'>Today  just a little  Oracle trick: the  all_arguments  view.&lt;br /&gt;&lt;br /&gt;On your  favourite Oracle Client   try this :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;select distinct package_name from all_arguments&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;span style="font-family:arial;"&gt;this  will  list every packages including  yours  on the  current schema.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;then try  this one:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;select distinct object_name&lt;br /&gt;from all_arguments where package_name like 'STANDARD'&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;this  will list every standard  functions installed. I've found it   useful  when  try to remember the exact syntax of "NUMTODSINTERVAL " or "NUMTOYMINTERVAL".&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;that's all  folks  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;hope this helps &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;comments are welcome&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111236712457878826?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111236712457878826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111236712457878826&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111236712457878826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111236712457878826'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/04/oracle-functions.html' title='oracle functions'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111176111710433718</id><published>2005-03-25T06:31:00.000-08:00</published><updated>2005-03-31T08:29:36.456-08:00</updated><title type='text'>link</title><content type='html'>I just register this blog to this site :&lt;a href="http://www.popdex.com/"&gt;www.popdex.com&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111176111710433718?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111176111710433718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111176111710433718&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111176111710433718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111176111710433718'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/03/link.html' title='link'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-111106811246032807</id><published>2005-03-17T05:38:00.000-08:00</published><updated>2007-03-21T06:06:11.676-07:00</updated><title type='text'>Quotes &amp; parameters</title><content type='html'>Saw this question on a newsgroup(&lt;a class="gl" href="http://groups-beta.google.com/group/microsoft.public.data.oledb"&gt;microsoft.public.data.oledb&lt;/a&gt; ) :&lt;br /&gt;&lt;br /&gt;&lt;em&gt;"How can legally include " ' " (single quote) in my SQL statement?"&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;This is a common question and many times it could be a security problem because of SQL injection. Single quote is the SQL string delimiter so you may have to avoid it from you sql code or double it in order to have a valid sql statement.&lt;br /&gt;&lt;br /&gt;There is a more elegant way to solve this problem: the use of parameters.&lt;br /&gt;&lt;br /&gt;lets say that cnx is a valid connection the syntax in c# for .net will be :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;OleDbDataAdapter daRes = new OleDbDataAdapter("SELECT IDT_EMP,EMP_NAME FROM EMP where IDT_EMP = ?",cnx);&lt;br /&gt;daRes.SelectCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("IDT_EMP", System.Data.OleDb.OleDbType.VarChar, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(4)), ((System.Byte)(0)), "IDT_EMP", System.Data.DataRowVersion.Current, null));&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;notice &lt;/u&gt;&lt;/strong&gt;:If you have many parameters all of them will be represent by a "?". You will have to follow the order of the ?s in the SQLstatement when you add your parameters to the oledbcommand parameters collection .&lt;br /&gt;&lt;br /&gt;that's all folks&lt;br /&gt;&lt;br /&gt;hope this helps !&lt;br /&gt;&lt;br /&gt;comments are welcome.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-111106811246032807?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/111106811246032807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=111106811246032807&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111106811246032807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/111106811246032807'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/03/quotes-parameters.html' title='Quotes &amp; parameters'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-110909160264004609</id><published>2005-02-22T08:58:00.000-08:00</published><updated>2005-03-03T03:25:01.103-08:00</updated><title type='text'>Oracle sequences and ADO .Net.</title><content type='html'>A few days ago, I twisted my brain on a tricky problem. The point was « the tables in the database have triggers witch inserts a sequence value when inserting a row. The client application uses a dataset and datatables objects with a master-detail relation which requires the primary key to be stored in the datatable objects »&lt;br /&gt;&lt;br /&gt;That is not a brand new problem. The sequence mechanism is database oriented. That is a good idea. When there are numerous users, it is better to use a centralized id generator. But, an advanced cache oriented data access API like ADO .NET needs to manage this unique identifier without synchronizes the entire dataset.&lt;br /&gt;&lt;br /&gt;So, last week, I desperately try to build a master/detail dataset model that does not need to know the primary keys of new entries. That was not an elegant solution. Neither it is to use the ADO .net autoId system (as it is client side oriented).&lt;br /&gt;&lt;br /&gt;I have founded the following solution.&lt;br /&gt;&lt;br /&gt;Let us have a table named EMP with the following fields:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;ID_EMP Number(6)&lt;br /&gt;EMP_NAME VARCHAR2(100)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;..And the following sequence:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;CREATE SEQUENCE PSI_ADMIN.S_EMP&lt;br /&gt;START WITH 1&lt;br /&gt;INCREMENT BY 1&lt;br /&gt;MAXVALUE 999999999999999999999999999&lt;br /&gt;MINVALUE 1&lt;br /&gt;NOCYCLE&lt;br /&gt;CACHE 20&lt;br /&gt;NOORDER;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A typical way to retrieve and manipulate values in .Net is to build dataAdapter object with the insert, delete, update and select Command.&lt;br /&gt;&lt;br /&gt;For instance:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;OleDbDataAdapter da = new OleDbDataAdapter() ;&lt;br /&gt;da.SelectCommand.CommandText= "SELECT ID_EMP,EMP_NAME FROM EMP"&lt;br /&gt;da.UpdateCommand.CommandText= "UPDATE EMP SET EMP_NAME= ? WHERE ID_EMP= ?" ;&lt;br /&gt;da.UpdateCommand.Parameters.Add("EMP_NAME",OleDbType.VarChar,100,"EMP_NAME");&lt;br /&gt;da.UpdateCommand.Parameters.Add("ID_EMP" , OleDbType.Numeric,6,"ID_EMP");&lt;br /&gt;da.InsertCommand.CommandText= "INSERT INTO EMP(ID_EMP,EMP_NAME) VALUES(?,?)";&lt;br /&gt;da.InsertCommand.Parameters.Add("ID_EMP" , OleDbType.Numeric,6,"ID_EMP");&lt;br /&gt;da.InsertCommand.Parameters.Add("EMP_NAME",OleDbType.VarChar,100,"EMP_NAME");&lt;br /&gt;da.DeleteCommand.CommandText= "DELETE EMP WHERE ID_EMP= ?" ;&lt;br /&gt;da.DeleteCommand.Parameters.Add("ID_EMP" , OleDbType.Numeric,6,"ID_EMP");&lt;br /&gt;&lt;br /&gt;da.SelectCommand.Connection = cnx ;&lt;br /&gt;da.UpdateCommand.Connection = cnx ;&lt;br /&gt;da.InsertCommand.Connection = cnx ;&lt;br /&gt;da.DeleteCommand.Connection = cnx ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;….where “cnx” is a valid OLEDB connection to the Oracle database.&lt;br /&gt;The "da" object may be use for instance to fill a dataset that can be itself manipulated by a datagrid:&lt;br /&gt;…&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;da.Fill(ds,"EMP");&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;…&lt;br /&gt;&lt;br /&gt;When synchronizing:&lt;br /&gt;…&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;da.Update(ds,"EMP");&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;…&lt;br /&gt;…where "ds" is a valid dataset.&lt;br /&gt;&lt;br /&gt;This code will works fine as long as you can provide a valid ID_EMP.&lt;br /&gt;If you want to use the Oracle sequence, and that is my point, you need something more.&lt;br /&gt;You need to handle the “update” event and retrieve the sequence’s next Val from Oracle.&lt;br /&gt;&lt;br /&gt;Here is how I implement this:&lt;br /&gt;First, handle the event in the dataAdapter’s construction:&lt;br /&gt;…&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;da.RowUpdating +=new OleDbRowUpdatingEventHandler(da_RowUpdating);&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;..&lt;br /&gt;In addition, somewhere else in the class, put the following method:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;private void da_RowUpdating(object sender, OleDbRowUpdatingEventArgs e)&lt;br /&gt;{&lt;br /&gt;// Is it an insertion ?&lt;br /&gt;if (e.StatementType == StatementType.Insert)&lt;br /&gt;da.InsertCommand.Parameters["ID_EMP"].Value= (new OleDbCommand("select S_EMP.nextval from Dual",cnx).ExecuteScalar());&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;When the dataAdapter’s Update method is called, this event fire for each new, deleted or updated row, just before the SQL action is performed.&lt;br /&gt;If the action’s type is “insert” the sequence‘s next Val replace the current id_emp parameter.&lt;br /&gt;&lt;br /&gt;That’s all folks!&lt;br /&gt;&lt;br /&gt;Hope this helps.&lt;br /&gt;&lt;br /&gt;Comments are welcome.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110909160264004609?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110909160264004609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110909160264004609&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110909160264004609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110909160264004609'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/02/oracle-sequences-and-ado-net.html' title='Oracle sequences and ADO .Net.'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-110803530883237162</id><published>2005-02-10T03:17:00.000-08:00</published><updated>2005-02-10T03:36:03.186-08:00</updated><title type='text'>Back to work </title><content type='html'>Hello everybody!&lt;br /&gt;Waow!  I didn't post for about 20 days! Sorry about this. I wasn't able to post because I was &lt;a href="http://travel-cuba.tripod.com/images/antigua/sandals-antigua/beach.jpg "&gt;here&lt;/a&gt; and also &lt;a href=" http://www2.canoe.com/archives/voyages/decouvrir/destinations/media/2002/02/20020227-120024-g.jpg"&gt;there&lt;/a&gt;, I've also been to &lt;a href="http://www.visit-the-virgin-islands.com"&gt;this place&lt;/a&gt; and &lt;a href="http://www.geographia.com/st-lucia"&gt;this one&lt;/a&gt;. &lt;br /&gt;Oups! I nearly forget this &lt;a href="http://www.top-saint-martin.com/english.htm"&gt;island&lt;/a&gt; and this &lt;a href="http://www.la-romana.net"&gt; one&lt;/a&gt;.  &lt;br /&gt;&lt;br /&gt;Sorry, that's hard to post code sample today. &lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110803530883237162?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110803530883237162/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110803530883237162&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110803530883237162'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110803530883237162'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/02/back-to-work.html' title='Back to work '/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-110650725031764840</id><published>2005-01-23T09:04:00.000-08:00</published><updated>2005-09-09T06:10:13.416-07:00</updated><title type='text'>Code generation and  self  description</title><content type='html'>A few weeks ago I proposed here an example of C# code generation.&lt;br /&gt;It remind me an old exercise I used to do when discovering a new language.&lt;br /&gt;"The shortest program which produce its own source code on the standard output."&lt;br /&gt;Of course,  programs which read explicitly their source code to reproduce it are not accepted.&lt;br /&gt;The idea of the exercise is to find self reference possibilities offers by the language.&lt;br /&gt;&lt;a href="http://mboizeau.free.fr/EXE/echo.exe"&gt;I've put the executable here&lt;/a&gt; and &lt;a href="http://oraclevsmicrosoft.blogspot.com/2005/06/self-description.html"&gt;the source code is here&lt;/a&gt;Just download and then launch the echo.exe then click the "itself" button , the complete source code is displayed in the upper richtext box. Then click the "compile" button , the source code is compiled and saved in c:\echo.exe (be careful not to replace a program of your owns).&lt;br /&gt;Just launch this new program and compare with the first one.... If you want, you can try to change the code to see effects (debug information shown in the second box).&lt;br /&gt;&lt;br /&gt;Briefly the principles:&lt;br /&gt;I used a double coding representation. The C# code contains in one point a string array declaration with all the lines of the code between "" and coma separated. All the line of the code ? Not exactly, the array declaration is replaced into the array itself by an arbitrary string (I choose a French poet's famous verses). When you click the "it self" button this exact string is replace by a construction of the array declaration. So at this time the array contains all the code including its own declaration. Then a "foreach" instruction join all the lines into one big string which is the exact source code.&lt;br /&gt;When you push the "compile" button the text box content is compiled .&lt;br /&gt;&lt;br /&gt;There is two key factors in this very solution (I'm sure there is at least another solution ).&lt;br /&gt;- The declaration syntax of an array in C# which authorize long static arrays.&lt;br /&gt;- The compilation feature of the .Net framework.&lt;br /&gt;&lt;br /&gt;The main part of the code is writed two times. Maybe there is no true connection with this but I can't help comparing this to the double-helix DNA in living cells.&lt;br /&gt;&lt;br /&gt;The comparison with living cells ends here. This code isn't (AFAIK) a kind of virus or worm and can't be used for malicious purpose. (For instance, runtime compiling features can't be used during an in-line context).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ok, now, two questions :&lt;br /&gt;&lt;br /&gt;- Is it possible to code that kind of program in PL-SQL? (;-))&lt;br /&gt;Maybe next time !&lt;br /&gt;- The array based solution is interesting but it doesn't imply the Icodegenerator interface. Is there a solution using a more sophisticated structure than an array?&lt;br /&gt;For instance is it possible that a program build its own abstract description usng this interface?&lt;br /&gt;&lt;br /&gt;That's all folks !&lt;br /&gt;Remember there is 10 sorts of people : those who understand native binary code and the others !&lt;br /&gt;&lt;br /&gt;Comments, answers and suggestions are welcome!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110650725031764840?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110650725031764840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110650725031764840&amp;isPopup=true' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110650725031764840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110650725031764840'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/01/code-generation-and-self-description.html' title='Code generation and  self  description'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-110604133691185725</id><published>2005-01-18T01:40:00.000-08:00</published><updated>2005-01-18T02:01:26.263-08:00</updated><title type='text'>links</title><content type='html'>A few links today:&lt;br /&gt;&lt;br /&gt;&lt;a href='http://www.dotnetspider.com'&gt;C# tutorial and offshore development&lt;/a&gt; - dotnetspider offers online training, C# tutorials, offshore development, software  outsourcing, link search and sample C# projects with source code.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blog.spsclerics.com "&gt;http://blog.spsclerics.com &lt;/a&gt;  A Colleague of mine. This blog is mainly about Microsoft Sharepoint portal Server. But you will also find  things about C#, .net technology (and the authour's hollidays;-) &lt;br /&gt;that's all folks &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110604133691185725?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110604133691185725/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110604133691185725&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110604133691185725'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110604133691185725'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/01/links.html' title='links'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-110563475136027428</id><published>2005-01-13T08:42:00.000-08:00</published><updated>2005-01-14T08:03:48.223-08:00</updated><title type='text'>Oracle data dictionary</title><content type='html'>Hello everybody (Happy coding and merry source code for 2005! )&lt;br /&gt;&lt;br /&gt;Today I would like to talk about Oracle data Dictionary.&lt;br /&gt;Without any administration tool it's possible to retrieve information about tables,views and constraints.&lt;br /&gt;To understand this article you need an Oracle client connected to a valid schema.&lt;br /&gt;(SQL+ for instance)&lt;br /&gt;&lt;br /&gt;First I suggest you to try this syntax:&lt;br /&gt;select * from DICT&lt;br /&gt;This query returns all the views dealing with this schema's dictionary, very useful to retrieve the exact name of a view. The dictionary contains a big amount of views, let's focus on a few one:&lt;br /&gt;&lt;br /&gt;Imagine you want to list all the tables you can acces in a schema, you may then try the following:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT * FROM ALL_TABLES&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;If you're not a DBA but a developer you may just be interested in your own tables. So try this one:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT * FROM ALL_TABLES&lt;br /&gt;WHERE OWNER ='My_name'&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;The same thing about views:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT * FROM ALL_VIEWS&lt;br /&gt;WHERE OWNER ='My_name'&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;Now imagine you need to know all the constraints of a table :&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT * FROM ALL_CONSTRAINTS&lt;br /&gt;WHERE&lt;br /&gt;table_name= 'My_table' &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;That is useful, but you may want something more fine tunned:&lt;br /&gt;What are the foreign keys?:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT * FROM ALL_CONSTRAINTS&lt;br /&gt;WHERE CONSTRAINT_TYPE= 'R'&lt;br /&gt;and table_name= 'My_table' &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;What is the primary key? :&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT * FROM ALL_CONSTRAINTS&lt;br /&gt;WHERE CONSTRAINT_TYPE= 'P'&lt;br /&gt;and table_name= 'My_table'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That's interesting but most of the time you need the name of a field. So, the following retrieves the list of all the fields included in the primary key:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT COLUMN_NAME FROM ALL_CONS_COLUMNS CC, all_constraints C&lt;br /&gt;where CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME&lt;br /&gt;and C.TABLE_NAME= 'My_Table'&lt;br /&gt;and C.CONSTRAINT_TYPE='P'&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;That's all folks !&lt;br /&gt;Hope this helps, comments are welcome!&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110563475136027428?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110563475136027428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110563475136027428&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110563475136027428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110563475136027428'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2005/01/oracle-data-dictionary.html' title='Oracle data dictionary'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-110425773847633828</id><published>2004-12-28T09:56:00.000-08:00</published><updated>2004-12-29T01:59:29.480-08:00</updated><title type='text'>Code generation  with .net</title><content type='html'>Hello, today I would like to introduce code generation with c# and .NET. (It may be usefull when dealing with repetitive Database access code).&lt;br /&gt;&lt;br /&gt;To start with this feature, here is a complete sample on how to build a ".exe" file, using natives code generation and compilation tools.&lt;br /&gt;&lt;br /&gt;The following code will produce, after compilation with csc.exe, a winform application.&lt;br /&gt;This application has one purpose: produce another application, a console one.&lt;br /&gt;Two framework's objects are important here: &lt;strong&gt;System.CodeDom.Compiler.ICodeGenerator &lt;/strong&gt;and &lt;strong&gt;System.CodeDom.Compiler.ICodeCompiler. &lt;/strong&gt;&lt;br /&gt;The first is a common interface to generate .net code. The second one is used to compile the code. Here I use the cSharp implementation of these interfaces to produce a basic console application.&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;strong&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ComponentModel;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Forms;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.CodeDom;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.CodeDom.Compiler;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.CSharp;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Specialized;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; WindowsApplication2&lt;br /&gt;{&lt;br /&gt;    &lt;span class="rem"&gt;/// Main form&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Form1 : System.Windows.Forms.Form&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; System.Windows.Forms.Button button1;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; System.Windows.Forms.RichTextBox rt1;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; System.Windows.Forms.ListBox listBox1;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; System.ComponentModel.Container components = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Form1()&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="rem"&gt;//&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Requis pour la prise en charge du Concepteur Windows Forms&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//&lt;/span&gt;&lt;br /&gt;            InitializeComponent();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="rem"&gt;/// Nettoyage des ressources utilisées.&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Dispose( &lt;span class="kwrd"&gt;bool&lt;/span&gt; disposing )&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt;( disposing )&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (components != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    components.Dispose();&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;base&lt;/span&gt;.Dispose( disposing );&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="preproc"&gt;#region&lt;/span&gt; Code généré par le Concepteur Windows Form&lt;br /&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="rem"&gt;/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas&lt;/span&gt;&lt;br /&gt;        &lt;span class="rem"&gt;/// le contenu de cette méthode avec l'éditeur de code.&lt;/span&gt;&lt;br /&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InitializeComponent()&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.button1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Windows.Forms.Button();&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.rt1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Windows.Forms.RichTextBox();&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.listBox1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Windows.Forms.ListBox();&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.SuspendLayout();&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// button1&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.button1.Location = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Point(432, 8);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.button1.Name = &lt;span class="str"&gt;"button1"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.button1.Size = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Size(232, 104);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.button1.TabIndex = 0;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.button1.Text = &lt;span class="str"&gt;"button1"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.button1.Click += &lt;span class="kwrd"&gt;new&lt;/span&gt; System.EventHandler(&lt;span class="kwrd"&gt;this&lt;/span&gt;.button1_Click);&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// rt1&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.rt1.Location = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Point(24, 16);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.rt1.Name = &lt;span class="str"&gt;"rt1"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.rt1.Size = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Size(384, 192);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.rt1.TabIndex = 1;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.rt1.Text = &lt;span class="str"&gt;"richTextBox1"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// listBox1&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.listBox1.Location = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Point(24, 224);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.listBox1.Name = &lt;span class="str"&gt;"listBox1"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.listBox1.Size = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Size(896, 251);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.listBox1.TabIndex = 3;&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Form1&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// &lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.AutoScaleBaseSize = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Size(5, 13);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.ClientSize = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Size(936, 526);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Controls.Add(&lt;span class="kwrd"&gt;this&lt;/span&gt;.listBox1);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Controls.Add(&lt;span class="kwrd"&gt;this&lt;/span&gt;.rt1);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Controls.Add(&lt;span class="kwrd"&gt;this&lt;/span&gt;.button1);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Name = &lt;span class="str"&gt;"Form1"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Text = &lt;span class="str"&gt;"Form1"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Load += &lt;span class="kwrd"&gt;new&lt;/span&gt; System.EventHandler(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Form1_Load);&lt;br /&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.ResumeLayout(&lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span class="rem"&gt;/// Point d'entrée principal de l'application.&lt;/span&gt;&lt;br /&gt;        [STAThread]&lt;br /&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;br /&gt;        {&lt;br /&gt;            Application.Run(&lt;span class="kwrd"&gt;new&lt;/span&gt; Form1());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Form1_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, System.EventArgs e)&lt;br /&gt;        {&lt;br /&gt;        &lt;span class="rem"&gt;//nothing special here &lt;/span&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; button1_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, System.EventArgs e)&lt;br /&gt;        {&lt;span class="rem"&gt;// here is starting the main part of the code:&lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;//&lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;//the CodeCompileUnit  is the  abstract code structure:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Create a new CodeCompileUnit to contain the program graph&lt;/span&gt;&lt;br /&gt;            CodeCompileUnit CompileUnit = &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeCompileUnit();&lt;br /&gt;            &lt;span class="rem"&gt;// Declare a new namespace called Samples.&lt;/span&gt;&lt;br /&gt;            CodeNamespace Samples = &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeNamespace(&lt;span class="str"&gt;"Samples"&lt;/span&gt;);&lt;br /&gt;            &lt;span class="rem"&gt;// Add the new namespace to the compile unit.&lt;/span&gt;&lt;br /&gt;            CompileUnit.Namespaces.Add( Samples );&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Add the new namespace import for the System namespace.&lt;/span&gt;&lt;br /&gt;            Samples.Imports.Add( &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeNamespaceImport(&lt;span class="str"&gt;"System"&lt;/span&gt;) );&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Declare a new type called Class1.&lt;/span&gt;&lt;br /&gt;            CodeTypeDeclaration Class1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeTypeDeclaration(&lt;span class="str"&gt;"echo"&lt;/span&gt;);&lt;br /&gt;            &lt;span class="rem"&gt;// Add the new type to the namespace's type collection.&lt;/span&gt;&lt;br /&gt;            Samples.Types.Add(Class1);&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//a variable declaration&lt;/span&gt;&lt;br /&gt;            CodeVariableDeclarationStatement Var = &lt;span class="kwrd"&gt;new&lt;br /&gt;CodeVariableDeclarationStatement("System.String"&lt;/span&gt;,&lt;span class="str"&gt;"str1"&lt;/span&gt;);&lt;br /&gt;            &lt;span class="rem"&gt;// Declare a new code entry point method&lt;/span&gt;&lt;br /&gt;            CodeEntryPointMethod Start = &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeEntryPointMethod();&lt;br /&gt;            &lt;span class="rem"&gt;// Create a new method invocation expression.&lt;/span&gt;&lt;br /&gt;            CodeMethodInvokeExpression cs1 =&lt;br /&gt;new CodeMethodInvokeExpression(&lt;br /&gt;                &lt;span class="rem"&gt;// Call the System.Console.WriteLine method.&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;&lt;br /&gt;newCodeTypeReferenceExpression("System.Console"&lt;/span&gt;), &lt;span class="str"&gt;"ReadLine"&lt;/span&gt;);&lt;br /&gt;            CodeAssignStatement as1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeAssignStatement(&lt;br /&gt;new CodeVariableReferenceExpression(&lt;span class="str"&gt;"str1"&lt;/span&gt;),cs1);&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Create a new method invocation expression.&lt;/span&gt;&lt;br /&gt;            CodeMethodInvokeExpression cs2 =&lt;br /&gt; new CodeMethodInvokeExpression(&lt;br /&gt;                &lt;span class="rem"&gt;// Call the System.Console.WriteLine method.&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeTypeReferenceExpression(&lt;span class="str"&gt;"System.Console"&lt;/span&gt;), &lt;span class="str"&gt;"WriteLine"&lt;/span&gt;);&lt;br /&gt;            cs2.Parameters.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; CodeVariableReferenceExpression(Var.Name));&lt;br /&gt;&lt;br /&gt;            Start.Statements.Add(Var);&lt;br /&gt;            &lt;span class="rem"&gt;// Add the new method code statement.&lt;/span&gt;&lt;br /&gt;            Start.Statements.Add( as1);&lt;br /&gt;            &lt;span class="rem"&gt;// Add the new method code statement.&lt;/span&gt;&lt;br /&gt;            Start.Statements.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; CodeExpressionStatement(cs2));&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// Add the code entry point method to the type's members collection&lt;/span&gt;&lt;br /&gt;            Class1.Members.Add( Start );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            System.IO.StringWriter Sw = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.IO.StringWriter();&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;        Microsoft.CSharp.CSharpCodeProvider provider =&lt;br /&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; CSharpCodeProvider();&lt;br /&gt;        System.CodeDom.Compiler.ICodeGenerator generator = provider.CreateGenerator(Sw);&lt;br /&gt;            CodeGeneratorOptions genOptions = &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeGeneratorOptions();&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;// The code generator should insert blank lines &lt;/span&gt;&lt;br /&gt;            genOptions.BlankLinesBetweenMembers = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                generator.GenerateCodeFromCompileUnit(CompileUnit,Sw,genOptions);&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception Exc)&lt;br /&gt;            {&lt;br /&gt;            System.Windows.Forms.MessageBox.Show (Exc.Message);&lt;br /&gt;            }&lt;br /&gt;            rt1.Text = Sw.ToString();&lt;br /&gt;&lt;br /&gt;&lt;span class="rem"&gt;///&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;//            Compilation &lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//instanciate csharp compiler&lt;/span&gt;&lt;br /&gt;            System.CodeDom.Compiler.ICodeCompiler MyCompiler = provider.CreateCompiler();&lt;br /&gt;            System.CodeDom.Compiler.CompilerParameters cp = &lt;span class="kwrd"&gt;new&lt;/span&gt; CompilerParameters();&lt;br /&gt;                        cp.GenerateExecutable = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;                        cp.CompilerOptions= &lt;span class="str"&gt;" /target:exe"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//where your exe will be  saved&lt;/span&gt;&lt;br /&gt;            cp.OutputAssembly = &lt;span class="str"&gt;"c:\\echo.exe"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="rem"&gt;// Invoke compilation.&lt;/span&gt;&lt;br /&gt;            CompilerResults cr = MyCompiler.CompileAssemblyFromSource ( cp,rt1.Text);&lt;br /&gt;        &lt;span class="rem"&gt;//&lt;/span&gt;&lt;br /&gt;        &lt;span class="rem"&gt;// Return the results of compilation.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//eventually load compilation output to the listbox (usefull to debug)&lt;/span&gt;&lt;br /&gt;            listBox1.DataSource=cr.Output;&lt;br /&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//where is it? &lt;/span&gt;&lt;br /&gt;            MessageBox.Show ( cr.PathToAssembly );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/strong&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110425773847633828?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110425773847633828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110425773847633828&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110425773847633828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110425773847633828'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/12/code-generation-with-net.html' title='Code generation  with .net'/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8912334.post-110328399500084641</id><published>2004-12-17T03:40:00.000-08:00</published><updated>2004-12-17T11:05:36.003-08:00</updated><title type='text'>Change all querytable in an Excel File </title><content type='html'>A quick way to change, for instance, the name of a table in each query of a file:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Dim q As QueryTableDim ws As Worksheet&lt;br /&gt;For Each ws In ActiveWorkbook.Worksheets &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;For Each q In ws.QueryTables &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;q.CommandText = Replace(q.CommandText,"MaChaine", "MaNouvelleChaine")&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Next&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Next&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Of  course dont forget to deeply test the result!&lt;br /&gt;&lt;br /&gt;Thanks to "ADE" on &lt;a class="gl" href="http://groups-beta.google.com/group/microsoft.public.fr.officexp"&gt;microsoft.public.fr.officexp&lt;/a&gt; who ask the question.&lt;br /&gt;&lt;br /&gt;That's all folks!&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110328399500084641?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110328399500084641/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110328399500084641&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110328399500084641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110328399500084641'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/12/change-all-querytable-in-excel-file.html' title='Change all querytable in an Excel File '/><author><name>Marc</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
