Pages

10/27/2010

Image Save/Retrieve C# Windows Form SQL Server

This tutorial will guide you to save or retrieve image from SQL Server in C#.

1. First of all we need a database in SQL Server which contains a table with only two columns one is 'id' of type 'int' and second is of 'image' of type 'image'.

2. Open SQL Server 2005 Express Management Studio and create new database. Name it according to your choice.

3. After successfully creating database create a table with two columns described in step 1.

4. Now Open Visual Studio 2008/2010.

5. Create a project of windows form.

6. In Design View of Form1(you can rename it to your choice) drag a control of picture box to the form with two buttons.

7. Change text of one button to Save and second to Retrieve.

8. Double click Save button to create event for double click.

9. In this event function, create an object of FileStream, a string and byte array. Or you can simply paste the code below.


FileStream fs;


string path = "C:\\Sunset.jpg";


fs = new FileStream(path, FileMode.Open, FileAccess.Read);


//a byte array to read the image


byte[] picbyte = new byte[fs.Length];


fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));


fs.Close();

10. Now below this create database connectivity and store this byte array(picbyte) to the image column in the database table you created in starting steps. OR you can use this code.

string cString = "Initial Catalog=DB NAME;Data Source=SQL SERVER INSTANCE;User ID=DB USER;Password=DB USER PASSWORD;";


SqlConnection connection = new SqlConnection(cString);


string query = "insert into TableName (ColumnName) values (@pic)";


connection.Open();
SqlParameter picparameter = new SqlParameter();


picparameter.SqlDbType = SqlDbType.Image;


picparameter.ParameterName = "pic";


picparameter.Value = picbyte;


SqlCommand cmd = new SqlCommand(query, connection);


cmd.Parameters.Add(picparameter);
if (cmd.ExecuteNonQuery() > 0)
MessageBox.Show("Image Saved");
connection.Close();

11. Now the image is saved in the database. You can see this by using query analyzer. Confirm it by the length of image column you will see when you will query it.

12. Now the image is successfully saved, its time to Retrieve it.

13. Drag another picture box to the Designer.

14. Double click the Retrieve button to create the double click event.

15. You can simply use the code below to show the image you saved in the second picture box.

string cString = "Initial Catalog=DatabaseName;Data Source=SQL Instance Name;User ID=DB user;Password=Db User Password;";


SqlConnection connection = new SqlConnection(cString);


SqlCommand command = new SqlCommand("select ColumnName from tableName where ID=1", connection);


connection.Open();


SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();


sqlDataAdapter.SelectCommand = new SqlCommand("select userimage from UserImages where imageID=" + Convert.ToInt32(txtID.Text), connection);


DataSet dSet = new DataSet();


sqlDataAdapter.Fill(dSet);


if (dSet.Tables[0].Rows.Count > 0)
{
MemoryStream ms = new MemoryStream((byte[])dSet.Tables[0].Rows[0]["userimage"]);
pictureBox2.Image = new Bitmap(ms);
}

Note: ID in the command is the id you will see in the database of the image just stored. You can get this id form UI by just giving a textbox to the user.

Now you have successfully saved/retrieved image in the SQL Database using C#.

Any queries then you may ask....


10/18/2010

♥♥ GENERAL KNOWLEDGE OF HOLY QURAN ♥♥



 

 

 

GENERAL KNOWLEDGE OF HOLY QURAN.  

 

No

QUESTION

ANSWER

1

How many Sura are in Holy Quran ?

114

2

How many Verses are in Holy Quran ?

6666

3

How many dots are in Holy Quran ?

1015030

4

How many over bar (zaber) are in Holy Quran ?

93243

5

How many under bar ( Zaer ) are in Holy Quran ?

39586

6

How many R u que are in Holy Quran ?

1000

7

How many stop ( Waqf ) are in Holy Quran ?

5098

8

How many Thashdeed are in Holy Quran ?

19253

9

How many letters are in Holy Quran ?

323671

10

How many p e sh are in Holy Quran ?

4808

11

How many Madd are in Holy Quran ?

1771

12

How many words are in Holy Quran ?

77701

13

How many parts of Holy Quran ?

30

14

How many time Besmillah Al-Rahmaan Al-Raheem is repeated ?

114

15

How many Sura start with Besmillah Al-Rahmaan Al-Raheem ?

113

16

How many time the word 'Quran' is repeated in Holy Quran ?

70

17

Which is the longest Sura of Holy Quran ?

Al-Baqarah.

18

Which is the best drink mentioned in Holy Quran ?

Milk.

19

The best eatable thing mentioned inHoly Quran is ?

Honey.

20

Which is the shortest Sura of Holy Quran ?

Qausar.

21

The longest verse of Holy Quran is in which Sura?

Al-Baqarah No.282

22

The most disliked thing by the God though Halal is ?

Divorce

23

Which letter is used for the most time in Holy Quran.?

Alaph

24

Which letter is used for the lest time in Holy Quran ?

Zaa.

25

Which is the best night mentioned in Holy Quran ?

Night of Qadar.

26

Which is the best month mentioned in Holy Quran ?

Ramzan.

27

Which is the biggest animal mentioned in Holy Quran ?

Elephant.

28

Which is the smallest animal mentioned in Holy Quran ?

Mosquito

29

How many words are in the longest Sura of Holy Quran ?

25500

30

How many words are in the smallest Sura of Holy Quran ?

42

31

Which Sura of Holy Quran is called the mother of Quran ?

Sura Hamd

32

How many Sura start with Al-Hamdullelah ?

Five: Hamd, Inaam, Kahf, Saba & Fatr.

33

Which Sura has the same number of verses as the number of Sura of Holy Quran ?

Taqveer, 114 verses.

34

How many Sura's name is only one letter ?

Three: Qaf, Sad & Noon.

35

How many Sura start with word " Inna " ?

Four sura - Fatha, Nuh,Qadr, Qausar.

36

Which Sura has the number of its verses equal to the number of Masumeen ?

Saf, 14 verses.

37

Which sura are called Musabbahat ?

Esra, Hadeed, Hsar, Juma, Taghabun & Aala.

38

How many sura are Makkahi and how many are Madni ?

Macci 86, Madni 28.

39

Which sura is on the name of tribe of Holy Prophet ?

Quresh

40

Which sura is called the heart of Holy Quran ?

Yaseen.

41

In which sura the name of Allah is repeated five time ?

Sura al-Haj.

42

Which sura are named Azaiam ?

Sajdah, Fusselat, Najum & Alaq.

43

Which sura is on the name of one Holy war ?

Sura Ahzaab.

44

Which sura is on the name of one metal ?

Sura Hadeed

45

Which sura does not starts with Bismellah ?

Sura Tauba.

46

Which sura is called ' Aroos-ul-Quran ?

Sura Rehman.

47

Which sura is considered as 1/3 of holy Quran ?

Sura Tauheed.

48

The name of how many sura are with out dot ?

Hamd, Raad, Toor, Room, Masad.

49

In which sura Besmillah came twice ?

Sura Naml..

50

How many sura start with the Initials ( Mukette'at )?

29 Sura.

51

Which Sura was revealed twice ?

Sura Hamd..

52

In which Sura the back biter are condemned ?

Sura Humzah.

53

In which Sura the name of Allah is repeated in every verse ?

Sura Mujadala.

54

In which Sura the letter 'Fa' did not come ?

Hamd.

55

Which Sura are called Muzetain ?

Falk & Nas.

56

Which are those Sura if their name are reversed remain the same ?

Lael & Tabbat.

57

Which is that Sura if its first letter is remove becomes the name of one of the city of Saudi Arab ?  

Sajdah

58

Which Sura start with word ' Tabara Kallazi' ?

Mulk & Furkan

59

Macci Sura were revealed in how many years ?

13 years

60

Madani Sura were revealed in how many years ?

10 years.

61

Which sura start with word Kad ?

Mujadala & Momenoon.

62

Which Sura is related to Hazrat Ali ?

Sura Adiat.

63

How many Sura are in 30th. Chapter ?

37

64

Which sura every verse ends with letter 'Dal ' ?

Tauheed.

65

Which Sura is revealed in respect of Ahllelbayet ?

Sura Dahr..

66

Which sura every verse ends with letter ' Ra '?

Qauser.

67

In which sura the creation of human being is mentioned ?

Sura Hijr V-26.

68

In which sura the regulations for prisoner of war is mentioned ?

Sura Nesa

69

Which sura is having the laws about marriage ?

Sura Nesa..

70

Which sura if its name is reversed becomes the name of one bird ?

Sura Room..

71

In which sura the story of the worship of cow of Bani Esra'iel is mentioned ?

Sura Taha..

72

In which sura the law of inheritance is mentioned?

Sura Nesa..

73

In which sura the Hegira of Holy Prophet is mentioned ?

Sura Infall.

74

In which Sura the 27 Attributes of God are mentioned ?

Sura Hadeed


 

 

 


 



Twitter Delicious Facebook Digg Favorites More