Welcome to my blog which contains anything and everything I feel is worthwhile sharing......

Tuesday, November 2, 2010

Import data from MS Excel to SQL Server 2008

INSERT INTO [DatabaseName].[dbo].[Table]
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\...\myFile.xls','Select Column1,Column2 from[SheetName$]')

* SheetName is the name you see at the bottom of each excel sheet
default values being Sheet1 etc.

Friday, October 29, 2010

Convert PictureBox into a byte stream

Byte[] b = new Byte[0];
b = cov(pictureBox1);

public Byte[] cov(PictureBox p)
{

System.IO.MemoryStream ms = new System.IO.MemoryStream();
p.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}

Sunday, August 1, 2010

Query: Get Column names of a table

select column_name from information_schema.columns
where table_name =''
order by ordinal_position


Wednesday, July 7, 2010

Pass Data Between Forms VS2008 C#

Passing data between multiple forms can be done through many ways. This is one of the simpler and clearer methods.Here we try to pass a user input from a form1 to other forms.
For a start start a Windows Forms project. Go to "Project" and add 2 more forms.
The 3 forms should look like this.



Form 1 has buttons to call both forms and form 2 has a button to call form3.

In form1 add the following code.

public string passNameF1
{
get { return textBox1.Text; }
}
the name "passNameF1" is irrelevant. Note that "get" is a keyword. and notice that there is no " ()" after the name.

Now move on to method 2 and add this code.

public string passNameF2
{
set { textBox1.Text = value; }
get { return textBox1.Text; }
}

Form2 can not only obtain data from form1 via "set" it can also provide the data for form3 via "get".

here "value" is also a keyword.

Do the same with the third form. Add the following.

public string passNameF3
{
set { textBox1.Text = value; }
}

we only need to set the values to textbox1 in form 3 so we dont use the "get" method here.

With that done we move back to form1. In the Click event of Form1 s button "Call FORM2"
we type


private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.passNameF2 = passNameF1;
f2.Show();
}


we create an instance of form2 and assign the value we "got" from the textbox and assign it to f2's "passnameF2" which will "set" the value to Form2's textBox1.

Similarly for the other button-click we add

private void button2_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.passNameF3 = passNameF1;
f3.Show();
}



Onto form2 now and form2 has a button click event to call form 3 here we add.

private void button1_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.passNameF3 = passNameF2;
f3.Show();
}

That's that. run the program and see.






Tuesday, April 27, 2010

What is an ORACLE INSTANCE???

The collection of allocated memory(the SGA) and the running processes( PMON,SMON,LGWR etc) on the server is called an "instance".

NOTE:Unless you are using Real Application Clusters (RAC), only one instance can attach itself to a database

"database" is the collection of datafiles on disk. These datafiles belong to your tablespaces. They are also the online redo log files, the parameter file, the password file, and the control files (Refers the Storage structure of the database)