<?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-01-23T03:10:19.659-08: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?max-results=100'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><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>100</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><entry><id>tag:blogger.com,1999:blog-8912334.post-110321936521561223</id><published>2004-12-16T09:47:00.000-08:00</published><updated>2004-12-16T09:49:58.890-08:00</updated><title type='text'>My Wiki contributions</title><content type='html'>These days, I created two wiki pages :&lt;br /&gt;&lt;a href="http://c2.com/cgi/wiki?MarcBoizeau"&gt;http://c2.com/cgi/wiki?MarcBoizeau&lt;/a&gt;&lt;br /&gt;and&lt;br /&gt;&lt;a href="http://c2.com/cgi/wiki?OracleVsMicrosoft"&gt;http://c2.com/cgi/wiki?OracleVsMicrosoft&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;have A look!&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110321936521561223?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110321936521561223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110321936521561223&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110321936521561223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110321936521561223'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/12/my-wiki-contributions.html' title='My Wiki contributions'/><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-110244374804524910</id><published>2004-12-07T10:16:00.000-08:00</published><updated>2004-12-07T10:22:28.046-08:00</updated><title type='text'>WIKIWIKI</title><content type='html'>I've found one of the most strange web site I ever sow.&lt;br /&gt;WIKIWIKI which means "quick quick" in Hawai.&lt;br /&gt;Everybody can post in one second  about everything. Every pages are editable by everybody.&lt;br /&gt;&lt;br /&gt;There is contributions about c# and Oracle  technolgies :&lt;br /&gt;&lt;a href="http://c2.com/cgi-bin/wiki?CsharpFeatures"&gt;http://c2.com/cgi-bin/wiki?CsharpFeatures&lt;/a&gt;&lt;br /&gt;&lt;a href="http://c2.com/cgi-bin/wiki?OracleDatabase"&gt;http://c2.com/cgi-bin/wiki?OracleDatabase&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;try it! just click on &lt;a href="http://c2.com/cgi-bin/wiki?edit=OracleDatabase"&gt;EditText&lt;/a&gt;  to edit yourself the OracleDatabase dedicated page.&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-110244374804524910?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110244374804524910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110244374804524910&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110244374804524910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110244374804524910'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/12/wikiwiki.html' title='WIKIWIKI'/><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-110242943188503374</id><published>2004-12-07T06:18:00.001-08:00</published><updated>2004-12-17T11:13:53.293-08:00</updated><title type='text'>Connect a .Net application to an Oracle Database 1</title><content type='html'>Hello,&lt;br /&gt;today I would like to talk about something that, I think, is very important when you want to build an Oracle and Microsoft based Application.&lt;br /&gt;I want to talk about the ways you can use to connect a .Net application to an Oracle Database. It is a very wide subject with many aspects. I will dedicate many post to this.&lt;br /&gt;&lt;br /&gt;Today, lets concentrate on architectural aspects.&lt;br /&gt;&lt;br /&gt;Okay you've got an Oracle Database and a Windows .Net Platform. How to go from here to there?&lt;br /&gt;&lt;br /&gt;1 - First of all, Oracle is a relational Database implementing the SQL standard, somewhere in your system you need to build&lt;br /&gt;SQL queries to acces your data(and your stored procedures calls).&lt;br /&gt;&lt;br /&gt;2 - Oracle is a secure application. You need some login informations to connect to the database.(database name, login,&lt;br /&gt;password)&lt;br /&gt;&lt;br /&gt;3 - Oracle is also a network based application. You need an Oracle Client to access the database.&lt;br /&gt;&lt;br /&gt;4 - Oracle and Microsoft are two different corporations. You need a specific - so called - middleware to make those two&lt;br /&gt;technologies talking together.&lt;br /&gt;&lt;br /&gt;5 - .Net provide an Object Oriented API. So, you need to manipulate some objects of this API to connect the application to&lt;br /&gt;the Oracle Client and retrieve the data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ok lets see that more deeply:&lt;br /&gt;&lt;br /&gt;1 - SQL. Ok nothing special about this. If You ever work with a relational database you know what I'm talking about.&lt;br /&gt;If you never, you can survive to this article by knowing that :&lt;br /&gt;In this language three keywords are important "select", "from" and "where" to get your column of data named "A" in a table&lt;br /&gt;named B, just ask: "Select A from B" if you just want the value which are greater than 1 ask "select A from B where A&amp;gt;1".&lt;br /&gt;Just remember that you can retrieves data, but also change it.&lt;br /&gt;&lt;br /&gt;2 - Those of you Who ever work with Oracle, Know how to connect to a database. Fo those of you Who never work with this&lt;br /&gt;system lets say that an Oracle server can run many Databases. Each database has its own name. Each database has its own&lt;br /&gt;groups of users. The database's administrator can gives the right to read or to write on a table to a specific user. So when&lt;br /&gt;you connect to a database you provide a"user name" and a "password" and the system authorize you or not to acces ressources&lt;br /&gt;regarding your rights. All applications need a database name, a login and a password.&lt;br /&gt;&lt;br /&gt;3 - The client computer needs what Oracle calls "Oracle connectivity" it means the basics software which allow the computer to act as client for Oracle. You may have to install these softwares yourself using an Oracle CD. You may also have to configure the tnsnames.ora file. It is a configuration file you find on every machine connected to Oracle. Common path is :&lt;br /&gt;&lt;br /&gt;&amp;lt;oracle installation directory&amp;gt;/network/admin/&lt;br /&gt;TNS is standing for "Transparent Network Substrate" which is a part of Oracle network protocol. To connect to your data base, this file must contains information about the server on which you database is. &lt;br /&gt;A databse entry of your tnsnames.ora is like the following:&lt;br /&gt;MY_DATABASE_NAME.WORLD =&lt;br /&gt; (DESCRIPTION =&lt;br /&gt;  (ADDRESS_LIST =&lt;br /&gt;   (ADDRESS = (PROTOCOL = TCP)(HOST = MY_SERVER_NAME)(PORT = 1521))&lt;br /&gt;  )&lt;br /&gt;  (CONNECT_DATA =&lt;br /&gt;   (SERVICE_NAME = My_SERVICE_NAME)&lt;br /&gt;  )&lt;br /&gt; )&lt;br /&gt;Ask your favorite database administrator for the MY_SERVER_NAME, and MY_SERVICE_NAME. &lt;br /&gt;Don't ask me any question about the ".world" I never understand why it is sometimes unnecessary and sometimes mandatory (ask this question to your DBA to) &lt;br /&gt;&lt;br /&gt;4 - Middleware. Ok now hard things begin. I call "middleware" any software which allow very differrent software to communicate each others. Whith microsoft You have different way to plug your application on a database. &lt;br /&gt;Here i 'm going to speak about two common methods. ODBC and OLE DB. &lt;br /&gt;ODBC is standing for "Open DataBase Connectivity" (forget the word "Open" lol). &lt;br /&gt;It is a microsoft standard and coms with most of windows operating systems. It is a kind of repository where all connection to databases are stored. An ODBC entry is named a Data Source Name(DSN). To configure a DSN, you choose an ODBC driver dedicate to your Database System. And then give the database, login and password info. &lt;br /&gt;For instance  to connect to "My_database" on windows XP:&lt;br /&gt;&lt;br /&gt;1 Open the configuration panel&lt;br /&gt;2 Choose "administration tools"&lt;br /&gt;3 Then click on ODBC data sources&lt;br /&gt;4 Choose the "System Data source" (you need administrator rights) &lt;br /&gt;5 click on "ADD.."&lt;br /&gt;6 Choose a database odbc drivers, here you may choose "Microsoft ODBC for Oracle" or something like "Oracle in OraHome92" &lt;br /&gt;7 A driver specific window pops up, put the DSN name(which you will use to acces it later), your database name, login and password. Often a "test" button allows you to check that you 've put the right arguments. &lt;br /&gt;8 validate &lt;br /&gt;&lt;br /&gt;That's it. you have configured 	a DSN for an ODBC connection. &lt;br /&gt;&lt;br /&gt;Good news, For OLE DB you don't need any configuration like this. in fact in that case, this layer is nearly transparent.&lt;br /&gt;&lt;br /&gt;5 - The objects. The .Net framework provide the System.Data API. The principles are&lt;br /&gt;- You build a "connection" object using a "connection string" (which will contain information related to the database the ODBC or OLEDB layer, and so on) &lt;br /&gt;- Then you build a "DATAadaptater" object which is dedicated to encapsulate the SQL strings.&lt;br /&gt;- Then you build a "dataset" object which will allow you to access the data and maybe put it into graphical object. &lt;br /&gt;&lt;br /&gt;for instance, if you connect via oleb your C# code will be close to this one :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Data.OleDb;&lt;br /&gt;using System.Xml;&lt;br /&gt;&lt;br /&gt;namespace oracle&lt;br /&gt;{&lt;br /&gt;public class oracleData&lt;br /&gt;{&lt;br /&gt;static string strConnect;//Connection String&lt;br /&gt;static OleDbConnection myConnection; //connnection object&lt;br /&gt;static OleDbDataAdapter myAdapter;// see it later&lt;br /&gt;static OleDbCommand mySelect; // select command&lt;br /&gt;static DataSet myDS;&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;//The connection string :&lt;br /&gt;strConnect ="Provider=\"OraOLEDB.Oracle.1\";User ID=MY_LOGIN;PASSWORD=My_Password;Data Source=My_database;Extended Properties=;Persist Security Info=False";&lt;br /&gt;&lt;br /&gt;//the connection itself&lt;br /&gt;myConnection = new OleDbConnection();&lt;br /&gt;myConnection.ConnectionString= strConnect; //affect the connection string&lt;br /&gt;myConnection.Open();//open the connection&lt;br /&gt;&lt;br /&gt;//SQL&lt;br /&gt;mySelect =new OleDbCommand("select * from dual ",myConnection);&lt;br /&gt;myAdapter = new OleDbDataAdapter(mySelect);&lt;br /&gt;&lt;br /&gt;//dataset&lt;br /&gt;myDS = new DataSet("MyDataSetName"); //instanciate the data set&lt;br /&gt;myAdapter.Fill(myDS,"MyTable"); //load the data into the dataset&lt;br /&gt;&lt;br /&gt;//An easy way to retrieve the content of a dataset : XML export&lt;br /&gt;myDS.WriteXml("c:\\data.xml",XmlWriteMode.WriteSchema);// double "\" because "\" is an escape character&lt;br /&gt;myConnection.Close();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;Assuming the oledb provider "OraOLEDB.Oracle.1"is installed, you can use this in a .cs file and compile it with csc.exe (locate in&lt;br /&gt;c:/window/microsoft .net/framework/v1.1.4322/ on my station)&lt;br /&gt;&lt;br /&gt;Take close attention to the connection string strConnect and replace the name of the database/login/password by yours.&lt;br /&gt;&lt;br /&gt;Ok thats all folks! (and that is enought for today)&lt;br /&gt;Comments are welcome!&lt;br /&gt;&lt;br /&gt;A colleague of mine says to me about this blog :"there's a lot of code"( lol). Next time I will try talk in a more "human" way.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&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-110242943188503374?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110242943188503374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110242943188503374&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110242943188503374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110242943188503374'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/12/connect-net-application-to-oracle.html' title='Connect a .Net application to an Oracle Database 1'/><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-110147085094500529</id><published>2004-11-26T03:42:00.000-08:00</published><updated>2007-02-27T04:02:54.366-08:00</updated><title type='text'>Mandelbrot in C# , the sources!</title><content type='html'>Hello everybody,&lt;br /&gt;yesterday I posted a link to &lt;a href="http://oraclevsmicrosoft.blogspot.com/2004/11/mandelbrot-in-c.html"&gt;mandelbrot in c#&lt;/a&gt; on the &lt;a href="http://groups.google.fr/groups?q=microsoft.public.dotnet.framework.drawing"&gt;microsoft.public.dotnet.framework.drawing&lt;/a&gt; usenet group . Morten Wennevik reply to me and argued that a lot of code were missing. So, today I post the complete sources. He also said that Visual studio isn't mandatory to build a .Net Windows application. He is right! So I will also give the way to compile it without Visual Studio .net, just with the framework:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1&lt;/strong&gt; Create a directory for the project&lt;br /&gt;&lt;strong&gt;Step 2&lt;/strong&gt; In this directory put a text file named fractalform.cs (personnaly I used a UTF-8 format with Notepad) containing the following:&lt;br /&gt;&lt;span style="font-size:0;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;using System;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Windows.Forms;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;namespace mandelbrot&lt;br /&gt;{&lt;br /&gt;&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 Form1 : System.Windows.Forms.Form&lt;br /&gt;{&lt;br /&gt;Complex C1,C2,C3;&lt;br /&gt;private System.Windows.Forms.Button trace;&lt;br /&gt;private System.Windows.Forms.PictureBox BoiteImage;&lt;br /&gt;private System.Windows.Forms.Label label1;&lt;br /&gt;private System.Windows.Forms.TextBox hgx;&lt;br /&gt;private System.Windows.Forms.TextBox hgy;&lt;br /&gt;private System.Windows.Forms.TextBox bdy;&lt;br /&gt;private System.Windows.Forms.TextBox bdx;&lt;br /&gt;private System.Windows.Forms.Label label2;&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 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;// 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.trace = new System.Windows.Forms.Button();&lt;br /&gt;this.BoiteImage = new System.Windows.Forms.PictureBox();&lt;br /&gt;this.hgx = new System.Windows.Forms.TextBox();&lt;br /&gt;this.hgy = new System.Windows.Forms.TextBox();&lt;br /&gt;this.bdy = new System.Windows.Forms.TextBox();&lt;br /&gt;this.bdx = 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.SuspendLayout();&lt;br /&gt;//&lt;br /&gt;// trace&lt;br /&gt;//&lt;br /&gt;this.trace.Location = new System.Drawing.Point(512, 8);&lt;br /&gt;this.trace.Name = "trace";&lt;br /&gt;this.trace.Size = new System.Drawing.Size(80, 32);&lt;br /&gt;this.trace.TabIndex = 12;&lt;br /&gt;this.trace.Text = "trace";&lt;br /&gt;this.trace.Click += new System.EventHandler(this.button1_Click);&lt;br /&gt;//&lt;br /&gt;// BoiteImage&lt;br /&gt;//&lt;br /&gt;this.BoiteImage.Location = new System.Drawing.Point(24, 56);&lt;br /&gt;this.BoiteImage.Name = "BoiteImage";&lt;br /&gt;this.BoiteImage.Size = new System.Drawing.Size(584, 416);&lt;br /&gt;this.BoiteImage.TabIndex = 13;&lt;br /&gt;this.BoiteImage.TabStop = false;&lt;br /&gt;//&lt;br /&gt;// hgx&lt;br /&gt;//&lt;br /&gt;this.hgx.Location = new System.Drawing.Point(32, 24);&lt;br /&gt;this.hgx.Name = "hgx";&lt;br /&gt;this.hgx.Size = new System.Drawing.Size(80, 20);&lt;br /&gt;this.hgx.TabIndex = 14;&lt;br /&gt;this.hgx.Text = "-1,5";&lt;br /&gt;//&lt;br /&gt;// hgy&lt;br /&gt;//&lt;br /&gt;this.hgy.Location = new System.Drawing.Point(128, 24);&lt;br /&gt;this.hgy.Name = "hgy";&lt;br /&gt;this.hgy.Size = new System.Drawing.Size(80, 20);&lt;br /&gt;this.hgy.TabIndex = 15;&lt;br /&gt;this.hgy.Text = "-1,5";&lt;br /&gt;//&lt;br /&gt;// bdy&lt;br /&gt;//&lt;br /&gt;this.bdy.Location = new System.Drawing.Point(304, 24);&lt;br /&gt;this.bdy.Name = "bdy";&lt;br /&gt;this.bdy.Size = new System.Drawing.Size(80, 20);&lt;br /&gt;this.bdy.TabIndex = 16;&lt;br /&gt;this.bdy.Text = "1,5";&lt;br /&gt;//&lt;br /&gt;// bdx&lt;br /&gt;//&lt;br /&gt;this.bdx.Location = new System.Drawing.Point(216, 24);&lt;br /&gt;this.bdx.Name = "bdx";&lt;br /&gt;this.bdx.Size = new System.Drawing.Size(80, 20);&lt;br /&gt;this.bdx.TabIndex = 17;&lt;br /&gt;this.bdx.Text = "1,5";&lt;br /&gt;//&lt;br /&gt;// label1&lt;br /&gt;//&lt;br /&gt;this.label1.Location = new System.Drawing.Point(88, 0);&lt;br /&gt;this.label1.Name = "label1";&lt;br /&gt;this.label1.Size = new System.Drawing.Size(64, 23);&lt;br /&gt;this.label1.TabIndex = 19;&lt;br /&gt;this.label1.Text = "hautgauche";&lt;br /&gt;//&lt;br /&gt;// label2&lt;br /&gt;//&lt;br /&gt;this.label2.Location = new System.Drawing.Point(272, 0);&lt;br /&gt;this.label2.Name = "label2";&lt;br /&gt;this.label2.Size = new System.Drawing.Size(64, 16);&lt;br /&gt;this.label2.TabIndex = 20;&lt;br /&gt;this.label2.Text = "BasDroite";&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(632, 470);&lt;br /&gt;this.Controls.Add(this.label2);&lt;br /&gt;this.Controls.Add(this.label1);&lt;br /&gt;this.Controls.Add(this.bdx);&lt;br /&gt;this.Controls.Add(this.bdy);&lt;br /&gt;this.Controls.Add(this.hgy);&lt;br /&gt;this.Controls.Add(this.hgx);&lt;br /&gt;this.Controls.Add(this.BoiteImage);&lt;br /&gt;this.Controls.Add(this.trace);&lt;br /&gt;this.Name = "Form1";&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 Form1());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;private void button1_Click(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;int nbPix=1000;&lt;br /&gt;double diagDest;&lt;br /&gt;&lt;br /&gt;int x,y;&lt;br /&gt;Bitmap Imag;&lt;br /&gt;Color col;&lt;br /&gt;int iDiv;&lt;br /&gt;Complex c= new Complex();&lt;br /&gt;&lt;br /&gt;//define the complex plan zone&lt;br /&gt;Complex cHG = new Complex(Convert.ToDouble( this.hgx.Text),Convert.ToDouble( this.hgy.Text));&lt;br /&gt;Complex cBD = new Complex(Convert.ToDouble(this.bdx.Text),Convert.ToDouble(this.bdy.Text));&lt;br /&gt;diagDest=Convert.ToDouble( this.hgx.Text)-Convert.ToDouble( this.bdx.Text);&lt;br /&gt;&lt;br /&gt;//instantiate the bitmap&lt;br /&gt;Imag = new Bitmap(nbPix ,nbPix);&lt;br /&gt;&lt;br /&gt;//scan the bitmap&lt;br /&gt;for(x=0;x&amp;lt;Imag.Size.Width;x++)&lt;br /&gt;for(y=0;y&amp;lt;Imag.Size.Height;y++)&lt;br /&gt;{&lt;br /&gt;//convert the pixel coordinate into a complex number&lt;br /&gt;c = new Complex(diagDest*x/nbPix,diagDest*y/nbPix)-cHG;&lt;br /&gt;&lt;br /&gt;//calculate divergence&lt;br /&gt;iDiv = c.diverg();&lt;br /&gt;&lt;br /&gt;//choose the color of the pixel&lt;br /&gt;if (iDiv &amp;gt;= 255)&lt;br /&gt;//if it converge it's black&lt;br /&gt;col = System.Drawing.Color.FromArgb(255,0,0,0);&lt;br /&gt;else //if it is not it depend of the speed&lt;br /&gt;col = System.Drawing.Color.FromArgb(128,iDiv,iDiv,iDiv);&lt;br /&gt;&lt;br /&gt;//set the pixel color&lt;br /&gt;Imag.SetPixel(x,y,col );&lt;br /&gt;}&lt;br /&gt;//draw the image&lt;br /&gt;BoiteImage.SizeMode = PictureBoxSizeMode.StretchImage ;&lt;br /&gt;BoiteImage.ClientSize = new Size(Imag.Size.Width, Imag.Size.Height);&lt;br /&gt;BoiteImage.Image = (Image) Imag ;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 3&lt;/strong&gt;Put a second file named cplx.cs&lt;br /&gt;containing the following&lt;br /&gt;&lt;span style="font-size:0;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;using System;// to include the basic libraries&lt;br /&gt;&lt;br /&gt;namespace mandelbrot//a namespace groups classes working together,&lt;br /&gt;{&lt;br /&gt;// The main class&lt;br /&gt;class Complex&lt;br /&gt;{&lt;br /&gt;//constants&lt;br /&gt;const int IMAX_ITER = 255 ;// number of iterations to estimate the divergence&lt;br /&gt;const double MODUL_LIMIT = 2;//&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public double x;//pretty close to c++ syntax,&lt;br /&gt;//"public" indicates that the users of the class can access this property...&lt;br /&gt;public double y;&lt;br /&gt;&lt;br /&gt;//////////////////////////&lt;br /&gt;//constructors&lt;br /&gt;&lt;br /&gt;//the basic one , do nothing but is mandatory for operators overloading&lt;br /&gt;public Complex()&lt;br /&gt;{}&lt;br /&gt;&lt;br /&gt;//the main constructor&lt;br /&gt;public Complex(double i, double j)&lt;br /&gt;{&lt;br /&gt;x = i;&lt;br /&gt;y = j;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//////////////////////////&lt;br /&gt;//Operators overloading&lt;br /&gt;&lt;br /&gt;//plus&lt;br /&gt;public static Complex operator +(Complex c1,Complex c2)&lt;br /&gt;{&lt;br /&gt;Complex temp = new Complex();&lt;br /&gt;temp.x = (c1.x)+(c2.x);&lt;br /&gt;temp.y = c1.y+c2.y;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;//minus&lt;br /&gt;public static Complex operator -(Complex c1,Complex c2)&lt;br /&gt;{&lt;br /&gt;Complex temp = new Complex();&lt;br /&gt;temp.x = (c1.x)-(c2.x);&lt;br /&gt;temp.y = c1.y-c2.y;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;// multiplication, a little more complicated&lt;br /&gt;public static Complex operator *(Complex c1,Complex c2)&lt;br /&gt;{&lt;br /&gt;Complex temp = new Complex();&lt;br /&gt;temp.x = c1.x*c2.x-c1.y*c2.y;&lt;br /&gt;temp.y = c1.y*c2.x+c1.x*c2.y;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/////////////////////&lt;br /&gt;//methods&lt;br /&gt;&lt;br /&gt;//Module, used to measure the complex number&lt;br /&gt;public double Module()&lt;br /&gt;{&lt;br /&gt;double temp;&lt;br /&gt;temp = System.Math.Sqrt( x*x+y*y);&lt;br /&gt;return temp ;&lt;br /&gt;}&lt;br /&gt;//use to measure the divergence of the complex number&lt;br /&gt;//the number return is use to define the color of the affix's point&lt;br /&gt;public int diverg()&lt;br /&gt;{&lt;br /&gt;int i=0 ;&lt;br /&gt;Complex c = new Complex(x,y) ;&lt;br /&gt;&lt;br /&gt;while (i&amp;lt;IMAX_ITER &amp;&amp;amp; c.Module()&amp;lt;MODUL_LIMIT)&lt;br /&gt;{&lt;br /&gt;c = c*c+this;//yep "*" and "+" are the operator we've just overload.&lt;br /&gt;i++;&lt;br /&gt;}&lt;br /&gt;return i;//the number of iteration is return to set the color&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 4&lt;/strong&gt; Now open a command line window on the directory you've just create.&lt;br /&gt;type the folowing:&lt;br /&gt;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe /target:winexe /recurse:*.*&lt;br /&gt;(You may have to replace C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\ by your computer's c# compiler path.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's all folks, thanks to Morten Wennevik!&lt;br /&gt;&lt;br /&gt;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-110147085094500529?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110147085094500529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110147085094500529&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110147085094500529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110147085094500529'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/11/mandelbrot-in-c-sources.html' title='Mandelbrot in C# , the sources!'/><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-110131628877658390</id><published>2004-11-24T09:04:00.000-08:00</published><updated>2006-03-02T01:08:33.176-08:00</updated><title type='text'>Mandelbrot  in C#</title><content type='html'>Last week I talked a lot about Oracle and SQL, Mr Gates may be jealous ;-), let’s have a look to the .Net platform. Today I’m just going to introduce C# and a few stuff of the winform namespace (connection to Oracle will come later, be patient).&lt;br /&gt;&lt;br /&gt;First of all, I work with Visual Studio .Net. If you want to understand something to this article you need this tool.&lt;br /&gt;&lt;br /&gt;At &lt;a href="http://www.istm.fr/uk/homepage_a.html"&gt;school&lt;/a&gt; I learned Object Oriented Programming with C++ and Java. C# syntax is very close to those languages. The three languages have in common “{“, inheritance, encapsulation, a lot of keywords and something like a cultural background.&lt;br /&gt;At &lt;a href="http://www.istm.fr/uk/homepage_a.html"&gt;school&lt;/a&gt; I also made a &lt;a href="http://www.google.com/search?hl=en&amp;q=benoit+mandelbrot"&gt;Mandelbrot &lt;/a&gt;set explorer in C++ as an OOP exercise. I find myself interesting to demonstrate C# coding with those fractal objects.&lt;br /&gt;&lt;br /&gt;To do this I will present an object oriented construction to make calculus with complex numbers and the Mandelbrot specific method . I will then show how to use the Complex class into a simple WinForm to design Mandelbrot‘s set pictures.&lt;br /&gt;&lt;br /&gt;OK, I won’t make a mathematical demonstration about Mandelbrot’s set here.&lt;br /&gt;You just have to know that it deals with complex numbers and that you can make strange and sometimes &lt;a href="http://images.google.com/images?hl=en&amp;amp;lr=&amp;q=mandelbrot+set"&gt;beautiful pictures &lt;/a&gt;with it.&lt;br /&gt;&lt;br /&gt;The idea is that when you multiply a complex number with itself and adds another complex number, this many times; it can grows up infinitely or converge to zero.&lt;br /&gt;If it converges to zero it is a part of the set, when it grows up it is not. And you can measure at what “speed” it grows up.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So, here is my complex numbers class:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;using System;// to include the basic libraries&lt;br /&gt;&lt;br /&gt;namespace WindowsApplication1//a namespace groups classes working together,&lt;br /&gt;{&lt;br /&gt;// The main class&lt;br /&gt;class Complex&lt;br /&gt;{&lt;br /&gt;//constants&lt;br /&gt;const int IMAX_ITER = 255 ;// number of iterations to estimate the divergence&lt;br /&gt;const double MODUL_LIMIT = 2;//&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public double x;//pretty close to c++ syntax,&lt;br /&gt;//"public" indicates that the users of the class can access this property...&lt;br /&gt;public double y;&lt;br /&gt;&lt;br /&gt;//////////////////////////&lt;br /&gt;//constructors&lt;br /&gt;&lt;br /&gt;//the basic one , does nothing but is mandatory for operators overloading&lt;br /&gt;public Complex()&lt;br /&gt;{}&lt;br /&gt;&lt;br /&gt;//the main constructor&lt;br /&gt;public Complex(double i, double j)&lt;br /&gt;{&lt;br /&gt;x = i;&lt;br /&gt;y = j;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//////////////////////////&lt;br /&gt;//Operators overloading, we define here basic operations on complex number&lt;br /&gt;&lt;br /&gt;//minus&lt;br /&gt;public static Complex operator -(Complex c1,Complex c2)&lt;br /&gt;{&lt;br /&gt;Complex temp = new Complex();&lt;br /&gt;temp.x = (c1.x)-(c2.x);&lt;br /&gt;temp.y = c1.y-c2.y;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;//plus&lt;br /&gt;public static Complex operator +(Complex c1,Complex c2)&lt;br /&gt;{&lt;br /&gt;Complex temp = new Complex();&lt;br /&gt;temp.x = (c1.x)+(c2.x);&lt;br /&gt;temp.y = c1.y+c2.y;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;// multiplication, a little more complicated&lt;br /&gt;public static Complex operator *(Complex c1,Complex c2)&lt;br /&gt;{&lt;br /&gt;Complex temp = new Complex();&lt;br /&gt;temp.x = c1.x*c2.x-c1.y*c2.y;&lt;br /&gt;temp.y = c1.y*c2.x+c1.x*c2.y;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/////////////////////&lt;br /&gt;//methods&lt;br /&gt;&lt;br /&gt;//Module, used to measure the complex number&lt;br /&gt;public double Module()&lt;br /&gt;{&lt;br /&gt;double temp;&lt;br /&gt;temp = System.Math.Sqrt( x*x+y*y);&lt;br /&gt;return temp ;&lt;br /&gt;}&lt;br /&gt;//use to measure the divergence of the complex number&lt;br /&gt;//the number return is use to define the color of the affix's point&lt;br /&gt;public int diverg()&lt;br /&gt;{&lt;br /&gt;int i=0 ;&lt;br /&gt;Complex c = new Complex(x,y) ;&lt;br /&gt;&lt;br /&gt;while (i&amp;lt;imax_iter&amp;&amp;amp;c.Module()&amp;lt;MODUL_LIMIT)&lt;br /&gt;{&lt;br /&gt;c=c*c+this;//yes * and + are the operator we've just overload&lt;br /&gt;}&lt;br /&gt;return i;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;So we have all the stuffs we need to decide if a complex number is a member of Mandelbrot’s set or not.&lt;br /&gt;Now let’s use it in a Winform.&lt;br /&gt;5 steps :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1&lt;/strong&gt; In Visual Studio .net, create a new C# “Windows Application” project.&lt;br /&gt;&lt;strong&gt;Step 2 &lt;/strong&gt;Add a new object to the project (project window), a class(.cs file) names "complex". Then replace all the code of the file by the preceding complex class code.&lt;br /&gt;&lt;strong&gt;Step 3 &lt;/strong&gt;In the design view of the form1.cs add:&lt;br /&gt;- A picture box named BoiteImage&lt;br /&gt;- Four text boxes named respectively:&lt;br /&gt;hgx(left and top X coordinate) default value:-0.5&lt;br /&gt;hgy(left and top Y coordinate) default value:-1&lt;br /&gt;bdx(right and bottom X coordinate) default value: 1.5&lt;br /&gt;bdy (right and bottom Y coordinate) default value: 1&lt;br /&gt;- A button named trace&lt;br /&gt;&lt;br /&gt;If your not familiar with Visual studio: you will find all those stuff in the “tool box” window You can change the names and default values by right clicking + properties over the created objects. Then find the “name “ or “defaultvalue” properties in the “properties” window.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 4&lt;/strong&gt; In the project window double click on the ”trace” button. You are now in the Onclick event implementation method.&lt;br /&gt;Put the following code into the “{ }”:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;int nbPix=1000;&lt;br /&gt;double diagDest;&lt;br /&gt;&lt;br /&gt;int x,y;&lt;br /&gt;Bitmap Imag;&lt;br /&gt;Color col;&lt;br /&gt;int iDiv;&lt;br /&gt;Complex c= new Complex();&lt;br /&gt;&lt;br /&gt;//define the complex plan zone&lt;br /&gt;Complex cHG = new Complex(Convert.ToDouble( this.hgx.Text),Convert.ToDouble( this.hgy.Text));&lt;br /&gt;Complex cBD = new Complex(Convert.ToDouble(this.bdx.Text),Convert.ToDouble(this.bdy.Text));&lt;br /&gt;diagDest=Convert.ToDouble( this.hgx.Text)-Convert.ToDouble( this.bdx.Text);&lt;br /&gt;&lt;br /&gt;//instantiate the bitmap&lt;br /&gt;Imag = new Bitmap(nbPix ,nbPix);&lt;br /&gt;&lt;br /&gt;//scan the bitmap&lt;br /&gt;for(x=0;x&lt;imag.size.width;x++) y="0;y&lt;Imag.Size.Height;y++)" idiv="c.diverg();" c="new"&gt;= 255)&lt;br /&gt;//if it converges it's black&lt;br /&gt;col = System.Drawing.Color.FromArgb(255,0,0,0);&lt;br /&gt;else //if it is not, it depends of the speed&lt;br /&gt;col = System.Drawing.Color.FromArgb(128,iDiv,iDiv,iDiv);&lt;br /&gt;&lt;br /&gt;//set the pixel color&lt;br /&gt;Imag.SetPixel(x,y,col );&lt;br /&gt;}&lt;br /&gt;//draws the image&lt;br /&gt;BoiteImage.SizeMode = PictureBoxSizeMode.StretchImage ;&lt;br /&gt;BoiteImage.ClientSize = new Size(Imag.Size.Width, Imag.Size.Height);&lt;br /&gt;BoiteImage.Image = (Image) Imag ;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Step 5 N&lt;/strong&gt;ow Hit F5 key and then click the « trace button » enjoy and change the range to explore the set!&lt;br /&gt;&lt;br /&gt;That’s all folks&lt;br /&gt;Sources and .exe on line soon !&lt;br /&gt;Comments are welcome&lt;br /&gt;&lt;br /&gt;Special thanks to my schoolmates Benoit and Jérôme .&lt;br /&gt;&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-110131628877658390?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110131628877658390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110131628877658390&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110131628877658390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110131628877658390'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/11/mandelbrot-in-c.html' title='Mandelbrot  in C#'/><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-110079096177214503</id><published>2004-11-18T07:13:00.000-08:00</published><updated>2007-03-28T21:31:57.880-07:00</updated><title type='text'>SQL Analytical : Rollup </title><content type='html'>&lt;span style="font-family:times new roman;"&gt;A few days ago, I started to introduce analytical SQL functions. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:times new roman;"&gt;After "group by grouping sets" and "rank over", let's talk about "Rollup".&lt;br /&gt;&lt;br /&gt;Let's suppose you have the following table :&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;create table SALES(&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;PRODUCT_NAME VARCHAR2(255 BYTE), &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;DAY NUMBER(2), &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;MONTH NUMBER(2), &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;YEAR NUMBER(4), &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;AMOUNT NUMBER(9)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:times new roman;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;Now, suppose you want to calculate the total amount for one day, the total amount for one month and for one year. You may use the "grouping sets" syntax. This is a powerfull feature which allow you many combinations. But have a look to this one:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:times new roman;"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;select PRODUCT_NAME,DAY ,MONTH ,YEAR, sum(AMOUNT) from sales group by rollup (YEAR,MONTH,PRODUCT_NAME)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;This&lt;/span&gt; syntax will return the sale's amount for one month and one product then for all the month , this for each month and then the grand total.&lt;br /&gt;Notice that you just need to specify your grouping level. Imagine your final application is something like a querying tool for instance an ASP .NET web form (I should talk about this in another post). You can propose your user a grouping level option button which modify dynamically the rollup field list, easily.&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;Now, let's suppose your table is not completed , some MONTH fields contains a NULL value. How can you make the difference between the real null value and the null value which is the mark of a group sum.&lt;br /&gt;There is a solution which help to see the difference for a querying tool, the "grouping" function.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;select PRODUCT_NAME,DAY ,MONTH ,YEAR, sum(AMOUNT), grouping(YEAR), grouping(MONTH),grouping(PRODUCT_NAME)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;from sales &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;group by rollup (YEAR,MONTH,PRODUCT_NAME)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;For instance the "grouping(YEAR)" column return 1 when the line is a sum for one year and the rest of the time. Then your Web form will be able to detect if the line is aggregate and on which level (you may want to change the font or color of the line) . You can also use it with a "decode" function for instance to put the text "Total" instead of the product_name. Let's try this :&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;select &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;decode(grouping(PRODUCT_NAME),1,'all product' ,PRODUCT_NAME), &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;decode(grouping(DAY),1,'all month',DAY), &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;decode(grouping(month),1,'all year', MONTH) , &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;YEAR,&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;sum(AMOUNT)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;from sales group by rollup (YEAR,MONTH,PRODUCT_NAME)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;Ok That's all folks , hope this help !Any comments are welcome!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110079096177214503?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110079096177214503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110079096177214503&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110079096177214503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110079096177214503'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/11/sql-analytical-rollup.html' title='SQL Analytical : Rollup '/><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-110054176136846056</id><published>2004-11-15T10:00:00.000-08:00</published><updated>2004-11-15T10:02:41.366-08:00</updated><title type='text'>Just another link today</title><content type='html'>&lt;a href="http://www.OracleMonster.com" target="_blank"&gt;Oracle Monster: Forums for Oracle DBAs and developers&lt;/a&gt; - Offers forums where you can get help with everything from SQL language and security to database design and optimization.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110054176136846056?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110054176136846056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110054176136846056&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110054176136846056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110054176136846056'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/11/just-another-link-today.html' title='Just another link today'/><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-110028230556037005</id><published>2004-11-12T09:52:00.000-08:00</published><updated>2004-11-12T10:07:38.403-08:00</updated><title type='text'> A few Oracle and Microsoft links</title><content type='html'>Today I would like to list a few of my favourites web sites.&lt;br /&gt;&lt;br /&gt;here is a good oracle sql reference :&lt;br /&gt;&lt;a href="http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96540/toc.htm"&gt;http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96540/toc.htm&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is a direct link to Microsoft .Net framework reference on msdn:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/netfxanchor.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/netfxanchor.asp&lt;/a&gt; .&lt;br /&gt;&lt;br /&gt;here are the google archives of usenet groups on which I made a contribution:&lt;br /&gt;&lt;a href="http://groups.google.com/groups?hl=en&amp;lr=&amp;amp;group=comp.databases.oracle.server"&gt;comp.databases.oracle.server&lt;/a&gt;&lt;br /&gt;&lt;a href="http://groups.google.com/groups?hl=en&amp;lr=&amp;amp;group=microsoft.public.excel.worksheet.functions"&gt;microsoft.public.excel.worksheet.functions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://groups.google.com/groups?hl=en&amp;lr=&amp;amp;group=microsoft.public.excel.misc"&gt;microsoft.public.excel.misc&lt;/a&gt;&lt;br /&gt;&lt;a href="http://groups.google.com/groups?hl=en&amp;lr=&amp;amp;group=microsoft.public.excel"&gt;microsoft.public.excel&lt;/a&gt;&lt;br /&gt;&lt;a href="http://groups.google.com/groups?hl=en&amp;lr=&amp;amp;group=sybase.public.sqlanywhere.general"&gt;sybase.public.sqlanywhere.general&lt;/a&gt;&lt;br /&gt;Good WE everybody&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-110028230556037005?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/110028230556037005/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=110028230556037005&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110028230556037005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/110028230556037005'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/11/few-oracle-and-microsoft-links.html' title=' A few Oracle and Microsoft 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-109999378741678741</id><published>2004-11-09T01:08:00.000-08:00</published><updated>2007-02-21T12:07:20.570-08:00</updated><title type='text'>Strange and usefull  Oracle SQL structure</title><content type='html'>hello everybody,&lt;br /&gt;&lt;br /&gt;Last week I talked a lot about how to get Oracle's data into Excel. I said that, in my opinion, Excel is not the right tool to re-structure and reformat datas. It is not an OLAP tool.&lt;br /&gt;Today I would like to talk about a few Oracle specific SQL syntax that may be usefull for that: "rank over" and "group by grouping sets"&lt;br /&gt;&lt;br /&gt;&lt;u&gt;"rank over"&lt;/u&gt;&lt;br /&gt;So what is this?&lt;br /&gt;Here is a sample code:&lt;br /&gt;Just imagine you have a table which contains the monthly turnover of the products: &lt;strong&gt;MONTHLY_TURNOVER &lt;/strong&gt;with the following fields &lt;strong&gt;PRODUCT_NAME,MONTH,YEAR, AMOUNT&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;select MONTH'/''YEAR', PRODUCT_NAME, Amount, rank() over(partition by MONTH, YEAR order by AMOUNT desc) Month_Rank from MONTHLY_TURNOVER order by YEAR asc, MONTH asc,Month_Rank asc;&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;This query returns all the products for each month, orders by decreasing amount of turnover with the rank of each product in the month.&lt;br /&gt;&lt;br /&gt;This query does not make any filtering action. Instead, there is ordering and creation of information. The"rank()" syntax creates a new piece of information : the rank in the month of the product.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now imagine you have 500 differents products. You may want to see only the 10 most important of each month. This may be obtained by the following syntax:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;select * from (&lt;br /&gt;select MONTH'/''YEAR', PRODUCT_NAME, Amount, rank() over(partition by MONTH, YEAR order by AMOUNT desc) Month_Rank from MONTHLY_TURNOVER order by YEAR asc, MONTH asc,Month_Rank asc)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;where Month_Rank&lt;10;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I suggest you to build this as an Oracle view and then to query it by filtering on the year field or by the period you are interested in.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;"group by grouping sets"&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;Did you ever work with MS Access report or Crystal Report? Then you must have seen these  features that permit you to make sums, averages or other aggregation functions at different levels in those reporting tools. For instance, you can calculate the sum of all the turnovers of your products year by year, month by month, and then product by product for one month.&lt;br /&gt;You can do the same things directly with Oracle.&lt;br /&gt;&lt;br /&gt;Using the same table as in the first paragraph, try the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;select sum(AMOUNT ) AMOUNT , MONTH,YEAR, PRODUCT_NAME&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;from (MONTHLY_TURNOVER)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;group by grouping sets ((MONTH,YEAR, PRODUCT_NAME),(MONTH,YEAR),(YEAR))&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;order by year, month, product_name;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;you will have the following result assuming you have two products and one year :&lt;br /&gt;&lt;br /&gt;AMOUNT MONTH YEAR PRODUCT_NAME&lt;br /&gt;---------------------------------------------------------&lt;br /&gt;10 1 2004 p1&lt;br /&gt;20 1 2004 p2&lt;br /&gt;30 1 2004&lt;br /&gt;15 2 2004 p1&lt;br /&gt;25 2 2004 p2&lt;br /&gt;40 2 2004&lt;br /&gt;. . .&lt;br /&gt;&lt;br /&gt;60 12 2004&lt;br /&gt;360 2004&lt;br /&gt;&lt;br /&gt;As you can see, the line that sums all the turnovers of one month does not have any value for "product_name". The line that sums all the year does not have any value for "product_name" and "month".&lt;br /&gt;&lt;br /&gt;I found this very usefull because if you have to do this kind of query usualy you need to use three "select from where " clauses and you need to repeat three times your "where" clause.&lt;br /&gt;Personnaly, I used it in a view to sum surfaces for different real estate assets. For each building I get the sum of the rented and the free surface, and the total.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ok that's all folks.&lt;br /&gt;&lt;br /&gt;Hope this will help developers as it helps me!&lt;br /&gt;Comments are welcome!&lt;br /&gt;&lt;br /&gt;&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-109999378741678741?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/109999378741678741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=109999378741678741&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109999378741678741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109999378741678741'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/11/strange-and-usefull-oracle-sql.html' title='Strange and usefull  Oracle SQL structure'/><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-109940254939386625</id><published>2004-11-02T05:21:00.000-08:00</published><updated>2007-01-25T13:38:06.033-08:00</updated><title type='text'>From the datawarehouse to the chart (part 2)</title><content type='html'>&lt;div align="left"&gt;Last week I introduce the MS Query feature of Excel.&lt;br /&gt;Let's talk today about a few tricks to optimize its utilization with Oracle.&lt;br /&gt;&lt;br /&gt;Ok first you may have notice that this a very slow feature. Changes to the source query are uneasy. You need to open the source query. Then to use an old fashion query defintion tool. And then to go back to the Excel file to finally realize that you have to change some criteria in the SQL code.&lt;br /&gt;&lt;br /&gt;How to speed up this? &lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt; &lt;/div&gt;&lt;u&gt;&lt;/u&gt;&lt;div align="left"&gt;&lt;u&gt;Use your knowledge of the database&lt;/u&gt;&lt;/div&gt;&lt;div align="left"&gt;Make Views. &lt;/div&gt;&lt;div align="left"&gt;It seems to be an easy-to-say thing but, to my point of view, this it is critical. I think that Excel by it self don't have to be a datamart and shouldn't. You should Use Oracle Views to reformat or re-structure your data. There is many standard and Oracle specific SQL statements which can help you for this (that is a good idea for a next post). &lt;/div&gt;&lt;div align="left"&gt; &lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;u&gt;Use routine to change SQL. &lt;/u&gt;&lt;br /&gt;You are the developper. You know where to get the information in the database.&lt;br /&gt;Most of the time you define your queries in your fovarite Oracle tool and not in Excel or MS Query. So you don't need a wizard to explore the database. Instead you may need, as I, a quick way to seek-and-destroy bugs.&lt;br /&gt;&lt;br /&gt;I prefer to use my own a VB statement (which will be not stored into the final file).&lt;br /&gt;Here is the sub I use :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Sub createquery(strODBC, strSQL, strDestinationRange, strNAme)&lt;br /&gt;With ActiveSheet.QueryTables.Add(strODBC, Destination:=Range(strDestinationRange))&lt;br /&gt;.CommandText = strSQL&lt;br /&gt;.Name = strNAme&lt;br /&gt;.FieldNames = True&lt;br /&gt;.RowNumbers = False&lt;br /&gt;.FillAdjacentFormulas = False&lt;br /&gt;.PreserveFormatting = True&lt;br /&gt;.RefreshOnFileOpen = False&lt;br /&gt;.BackgroundQuery = True&lt;br /&gt;.RefreshStyle = xlInsertDeleteCells&lt;br /&gt;.SavePassword = False&lt;br /&gt;.SaveData = True&lt;br /&gt;.AdjustColumnWidth = True&lt;br /&gt;.RefreshPeriod = 0&lt;br /&gt;.PreserveColumnInfo = True&lt;br /&gt;.Refresh BackgroundQuery:=False&lt;br /&gt;End With&lt;br /&gt;End Sub&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;strODBC is the an ODBC string something like :&lt;br /&gt;ODBC;DSN=DSNName;UID=USer_ID;PWD=Password;DBQ=SCHEMA_NAME;"&lt;br /&gt;strSQL is the SQL statement you want to execute here&lt;br /&gt;strDestinationRange is something like "B2" or "$A$12:$H$52"&lt;br /&gt;&lt;br /&gt;You should use this statement carefully at your own risq and, off course, fit it to your needs.&lt;br /&gt;&lt;br /&gt;Notice that you may change the ODBC string structure, for instance if you omit thePassword excel will prompt you to logon. Notice  that&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Using parameters. &lt;/u&gt;&lt;br /&gt;&lt;u&gt;&lt;/u&gt;&lt;br /&gt;Parameters allow you to change criteria of a query without any VB code.&lt;br /&gt;Here is the way I use parameters in MS query :&lt;br /&gt;I use my favorite Oracle developpement tool and make a SQL query without parameters for instance :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;select name from customers where max_ammount&gt;1000&lt;br /&gt;and min_amount &lt;100&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:0;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;here is the versions with parameters &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;select name from customers where max_ammount&gt;?&lt;br /&gt;and min_amount &lt; ?&lt;?&lt;? &lt;/strong&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;Yes, there is no named parameters. Excel have specifical way to bind those things, just using order.&lt;br /&gt;&lt;br /&gt;Try it, for instance with the preceding VB code, or with the MS Query tool.&lt;br /&gt;When refreshing the data, Excel ask you to fill those parameters. &lt;/div&gt;&lt;br /&gt;At any time you can specify the source for each parameters:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Right click on the range of data. &lt;/li&gt;&lt;li&gt;Choose "parameters"&lt;/li&gt;&lt;li&gt;Select the parameter you &lt;/li&gt;&lt;li&gt;Then select the option you want for each parameter. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The first option is interesting. It allows you set the text of a question which will be asked to the user for this parameter. &lt;/p&gt;&lt;p&gt;Notice that when you use VB code to create a query with parameter, Excel gives default names to these parameters. If you want set your own names use the following syntax in a vb module :&lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Dim qt As QueryTable&lt;br /&gt;&lt;br /&gt;Set qt = ActiveSheet.QueryTables("MyQuery")&lt;br /&gt;&lt;br /&gt;qt.Parameters("Parameter1").Name = ("myFirstParam")&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;qt.Parameters("Parameter2").Name = ("mySecondParam")&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;All properties of parameters seems to be reachable by rightclick-&gt;parameters but the name which can be change only by code.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;u&gt;Charts &lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;Now  you know  how to  make  get data from parameterized query over Oracle into your Excel workbook, I suggest you the following if you need to produce many charts from yout  datawarehouse.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;I - Let's suppose you  have built  a  View  describing the monthly 's turnover of your products.  In a  new  excel sheet type-in the  product id of one of your products, build a query like the following :&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Select MonthNumber, turnover from  v_monthly_turn where  product_Id = ? and year = 2004&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span &gt;&lt;span &gt;II - When the wizard prompt you&lt;/span&gt;  for the parameter's value,   select  a  cell  which  contains  your product's ID and check the box to make this permanent.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;III - When the data are returned  select the range. Click on the chart button an choose your chart's  style and  location.&lt;/p&gt;&lt;p&gt;IV - Change your product's ID and refresh the  data by  right click-&gt;refresh data  over the data range.  &lt;/p&gt;&lt;p&gt;You may customise  this:&lt;/p&gt;&lt;p&gt;Instead of a cell based parameter use a parameter whith a question like "What is the product ID?" .  You may then set the "Refresh on file open" property to yes :(right click on the range then "properties") your  file  will then become  a little decisional tool. And this without any VB code! &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;That 's all for today  thank you for your attention. &lt;/p&gt;&lt;p&gt;All comments are welcome.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-109940254939386625?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/109940254939386625/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=109940254939386625&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109940254939386625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109940254939386625'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/11/from-datawarehouse-to-chart-part-2.html' title='From the datawarehouse to the chart (part 2)'/><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-109906950573251471</id><published>2004-10-29T09:24:00.000-07:00</published><updated>2004-11-02T04:33:04.396-08:00</updated><title type='text'>From the datawarehouse to the chart (part 1)</title><content type='html'>After Access lets use Excel as a client for Oracle.&lt;br /&gt;&lt;br /&gt;I work for a real estate company where assets managers always want to make charts or calculus based on data stored in the Oracle dataWarehouse. Most od the time they want to do this with Excel because well known this tool. Sometimes they want to use Excel just because its easy to format data and then to put it in a Powerpoint document.&lt;br /&gt;&lt;br /&gt;The problem is that we do not want to use VB macro in those Excel files . Those files may be sent by e-mail to clients. Any good firewall will destroy such files.&lt;br /&gt;&lt;br /&gt;One solution is to generate files on a server. For instance you install Oracle's client and office on a Windows 2003/IIS5 server and implement complex ASP/ASPX pages which generate Excel files .&lt;br /&gt;You may also use a Excel intepreted ASP page. Both of this solutions are hard to set up and need a  lot of  code. &lt;br /&gt;&lt;br /&gt;There is another solution: lets use MS Query! &lt;br /&gt;&lt;br /&gt;First of all your users need:&lt;br /&gt;- Oracle connectivity install and MS Excel on there computer.&lt;br /&gt;- A Data Source Name configure on there computer .&lt;br /&gt;- A login and password which they can use to access the database.&lt;br /&gt;&lt;br /&gt;I assume you work with  Windows NT/XP and got an Oracle Server.  &lt;br /&gt;Here is  how to get  data  from  Oracle:&lt;br /&gt;- create a new Excel document.&lt;br /&gt;- in the "data" menu choose "External data" then "new query"&lt;br /&gt;-Choose the appropriate Data Source Name&lt;br /&gt;- Logon&lt;br /&gt;- A wizard will guide you to make your select statement.&lt;br /&gt;- choose return to Excel and validate.&lt;br /&gt;&lt;br /&gt;surprise you've got your datas into Excel !&lt;br /&gt;&lt;br /&gt;That's all folks! Any comments are welcome!&lt;br /&gt;&lt;br /&gt;Next time I will try to expose how to fine tune this feature.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&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-109906950573251471?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/109906950573251471/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=109906950573251471&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109906950573251471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109906950573251471'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/10/from-datawarehouse-to-chart-part-1.html' title='From the datawarehouse to the chart (part 1)'/><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-109897837745945165</id><published>2004-10-28T07:58:00.000-07:00</published><updated>2004-10-29T09:23:39.683-07:00</updated><title type='text'>Using updatable views in Access</title><content type='html'>These "updatable views" feature in Oracle is interesting. You can specify triggers on a view to make it behaves like a table. Its interesting when different processes or applications use the same data but not the same way.&lt;br /&gt;How to make this working with Microsoft Access?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First define your view with a statement like the following:&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;create view MyView as select .......&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;then add your trigger(s) :&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;create or replace trigger MyUpdateTrigger&lt;br /&gt;INSTEAD OF UPDATE ON MyView as&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;begin &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:courier new;"&gt;update MyUnderlyingTable ut&lt;br /&gt;set ut.Field = new.ViewField&lt;br /&gt;where ut.keyfield new.keyfield ;&lt;br /&gt;end;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;notice the "instead of " statement . You may also add "delete" or "insert" triggers the same way.&lt;br /&gt;&lt;br /&gt;Now, how do you make Access 2003, your favorite client side application , works with this?&lt;br /&gt;Open your Access database and link the view as you would for a table.&lt;br /&gt;To do this:&lt;br /&gt;&lt;br /&gt;- In the file menu choose "external data" and "link table" . Then choose or create the Data Source Name which map your Oracle Database.&lt;br /&gt;&lt;br /&gt;- You will then be prompt to log with your Oracle Profile. You need to be familiar with ODBC and DSN (that is an idea for a new post).&lt;br /&gt;&lt;br /&gt;-Then Access display a list of all views and tables available. Depending of your profile you may see system tables and views. Choose "MyView".&lt;br /&gt;&lt;br /&gt;- You are then prompt to define the unique identifier of this "table". Choose it regarding the trigger's code you've implement. It should be the logical equivalent of a primary key.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now your view is available in Access. And it works!&lt;br /&gt;&lt;br /&gt;No it dosen't. In fact it works but it is not a practical way to build an application and test it.&lt;br /&gt;&lt;br /&gt;If you make a change to your view's definition the linked table in Access is no more available.&lt;br /&gt;So debugging a complex application with this is like a turtle race: you need to pe patient ;-).&lt;br /&gt;&lt;br /&gt;Here is a sample VB Access code which may help you :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Sub ConnectTable(strNomTable, strNomtablesource, strODBC, strKEy)&lt;br /&gt;Dim bds As Database, dft As TableDef&lt;br /&gt;Dim strSql&lt;br /&gt;Dim oFi As Field&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;Set bds = CurrentDb&lt;br /&gt;&lt;br /&gt;'delete the existing table&lt;br /&gt;If TableExists(strNomTable) Then&lt;br /&gt;CurrentDb.TableDefs.Delete (strNomTable)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Set dft = bds.CreateTableDef(strNomTable)&lt;br /&gt;&lt;br /&gt;dft.Connect = strODBC&lt;br /&gt;dft.SourceTableName = strNomtablesource&lt;br /&gt;&lt;br /&gt;bds.TableDefs.Append dft&lt;br /&gt;If Strings.Trim(strKEy) &lt;&gt; "" Then&lt;br /&gt;strSql = "CREATE INDEX " &amp; strNomTable &amp;amp; "_PK" &amp; " ON " &amp;amp; strNomTable &amp; "(" &amp;amp; strKEy &amp; ") WITH PRIMARY"&lt;br /&gt;bds.Execute strSql&lt;br /&gt;End If&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;strong&gt;fin:&lt;br /&gt;Set dft = Nothing&lt;br /&gt;Set bds = Nothing&lt;br /&gt;End Sub&lt;/strong&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:times new roman;"&gt;Put this in a module and call it with the following parameters:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:times new roman;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:times new roman;"&gt;strNomTable is the name of the Access linked table object. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:times new roman;"&gt;strNomtablesource is the Oracle view 's name, it may include a schema prefix. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:times new roman;"&gt;strODBC is the ODBC connection string matching you oracle database.&lt;br /&gt;it should be like the following : "ODBC;DSN=DSN_name;DBQ=oracle_schema_name;PWD=Password;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;DATABASE=" notice that here you have to provide a password, the one matching the user name provided in the DSN.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:times new roman;"&gt;strKey is the coma separated list of fields defining the unique identifier for the view.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:times new roman;"&gt;That's all folks! Comments are welcome!&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8912334-109897837745945165?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/109897837745945165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=109897837745945165&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109897837745945165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109897837745945165'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/10/using-updatable-views-in-access.html' title='Using updatable views in Access'/><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-109897061208139196</id><published>2004-10-28T06:25:00.000-07:00</published><updated>2004-10-28T06:49:08.716-07:00</updated><title type='text'>Introduction</title><content type='html'>Hello,&lt;br /&gt;I'm a french developper. I spend spend most of my time at work searching solutions to problems like :&lt;br /&gt;" How can we get the &lt;strong&gt;data&lt;/strong&gt;( in Oracle database) into the &lt;strong&gt;document&lt;/strong&gt; (Microsoft Office file)"&lt;br /&gt;or&lt;br /&gt;".Net studio is cool use it! You won't use SQL Server as as Database use Oracle for your applications"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&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-109897061208139196?l=oraclevsmicrosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oraclevsmicrosoft.blogspot.com/feeds/109897061208139196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8912334&amp;postID=109897061208139196&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109897061208139196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8912334/posts/default/109897061208139196'/><link rel='alternate' type='text/html' href='http://oraclevsmicrosoft.blogspot.com/2004/10/introduction.html' title='Introduction'/><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>
