Pages

12/28/2010

Running SQL Server Compact on WINCE--Tutorial

Recently i had to use SQL server in WINCE which was installed on Friendly ARM device. I had to go through some R&D to find it. Got some errors in the beginning but finally was able to do so. Just to be simple on the new image of WINCE just copy these cab files from the pc and copy them to TEMP folder in the WINCE.

You can find these cab files in the Program Files/SQL Server Compact in ARM folder. You will also need a .NET cab file which you can get from Framework installed directory. If you have Visual Studio 2008 installed you can get them easily you don't need to download these.

The files are
1. NETCFv35.wce.armv4
2. sql.wce5.armv4i
3. sqlce.dev.ENU.wce5.armv4i
4. sqlce.repl.wce5.armv4i
5. sqlce.wce5.armv4i

After copying these files in TEMP folder in WINCE double click each of them to install them one by one. Install them on the default path (Recommended).

Now you can run SQLCE commands in your application using C# or any language . If any one of these files are not installed properly you may not be able to run the SQL Server Compact.

The database file is .sdf which will be used in WINCE. You can create this DB file in SQL Server Management 2008. On startup just select database engine type to compact and create the file. Then copy it to the WINCE and you are good to go.

How to connect to it will be in next tutorial....

Queries are welcomed..


11/21/2010

Image Store Save/Retrieve C# Web SQL Server using Handler/ Generic Handler

This tutorial is to guide you to save/retrieve image using C# in ASP.Net Web

The saving image process is same as the windows form saving image process. You can get detail on my other tutorial which i wrote earlier which guide you to save/retrieve image in Windows Forms. You can read that tutorial from Click Here

For you ease i will copy past the code to show you how you save image in SQL server using 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 Web.

6.. In this event function of button you are using to save the image, 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();

7. 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();

8. 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.

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

10. Retrieving and showing image in web is slightly different from windows form.

11. You need handler to show image.

12. You can add handler from right clicking the web project and adding new item.

13. Handler got the extension of .ashx. E.g. when you added handler from adding new item you get Handler.ashx. You can rename it to whatever you want.

14. Now you need a image control in the web page to show the image. You can use asp:image and in its ImageUrl attribute write handler's URl like

ImageUrl="~/Handler.ashx"

15. '~' sign is to get the project starting location. If its in any folder then write its name first after ~ sign.

16. In handler.ashx you will retrieve the image and show it. You can send the image id or user id to the handler if you want to show image at runtime depending on the user. Basically used in dynamic sites. You can send id like this

ImageUrl="~/Handler.ashx?id=1"

17. Handler code looks like

public void ProcessRequest (HttpContext context)
{
try
{
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
context.Response.ContentType = "image/jpg";
conDB = new System.Data.SqlClient.SqlConnection("Data Source=SERVER Name;Initial Catalog=DB Name;Integrated Security=True;");
conDB.Open();
int id = 'id of the user or image You can get it from URL also if you send it to handler by REQUEST';
string str = "Select (Image) from TableName where UserID or ImageID =" + id;
System.Data.SqlClient.SqlCommand cmd = new SqlCommand(str, conDB);
System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
byte[] img = (byte[])reader["Image"];
reader.Close();
memoryStream.Write(img, 0, img.Length);
context.Response.Buffer = true;
context.Response.BinaryWrite(img);
memoryStream.Dispose();
conDB.Close();
context.Response.OutputStream.Write(img, 0, img.Length);
context.Response.BinaryWrite(img);
}
catch (Exception ex)
{
context.Response.Redirect("Error.aspx");
}
}

18. Now the Image will be shown in the asp:image after retrieval from Database.

19. One handler is enough to show as many images you want to show in the web site.

Queries are welcomed........


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


 

 

 


 



6/22/2010

Getting Specific Row in SQL 2000 & 2005

Here is the query to find the specific row in Sql 2000

SELECT ( SELECT SUM(1)

FROM [Table_Name]
WHERE [TableID]<=reg.[TableID]
) AS Row
,*
FROM
[Table_Name] AS reg
WHERE ( SELECT SUM(1)

FROM [Table_Name]
WHERE [TableID]<=reg.[TableID]
) = 5

Note: 5 is the row number you want to find in the table.

Now for SQL 2005

SELECT us.TableID
FROM (SELECT ROW_NUMBER() OVER (ORDER BY [Table_Name].[TableID]) AS Row,
[Table_Name].[TableID]
FROM [Table_Name] ) us
WHERE Row = 5

In this built in function ROW_NUMBER is used. Again '5' is the row number you are looking for. u can change it with the row number u want to find.


2/09/2010

Multiple Selection in RadComboBox--- Getting selectedValue at server side-- Setting selected value javascript

This article shows how to select multiple items in radcombobox and to get these selected values at server side. Also it shows how to show selected value in radcombobox using javascript.

1.First of all declare radcombobox.


<telerik:RadComboBox ID="ddlVehicleOwners" OnClientSelectedIndexChanging="onSelectedIndexChangingVehicleOwner" runat="server" Skin="WebBlue" OnClientDropDownClosed="HandleClose" LoadingMessage="Loading..." >
                                            <ItemTemplate>
                                                <table width="100%" cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td width="5%">
                                                            <asp:CheckBox ID="CheckBox" runat="server" Text='<%# Eval("DataFieldName") %>' />
                                                        </td>
                                                        <td align="left">
                                                            <asp:Label ID="lblVName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"DataFieldName") %>'
                                                                Visible="false"></asp:Label>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </ItemTemplate>
                                        </telerik:RadComboBox>

The label visible is false because it will have the text representing the id of that record.


2. Now in the head portion of the page use javascript to show selectedvalues in the radcombobox.



function HandleClose(comboBox)
        {
            var selectedData = "";
            var items = comboBox.get_items();
            for (var i = 0; i < items.get_count(); i++)
            {
                var itemDiv = items.getItem(i).get_element();
                var inputs = itemDiv.getElementsByTagName("input");
                var inputsData = itemDiv.getElementsByTagName("label");
                for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
                {
                    var input = inputs[inputIndex];
                    if (input.type == "checkbox")
                    {
                        if (input.checked == true)
                            selectedData = selectedData + inputsData[inputIndex].innerText+",";
                    }
                }
            }
            comboBox.set_text(selectedData.substring(0, selectedData.length - 1));
        }



3. Now final step to get values at server side.


foreach (RadComboBoxItem item in ddlVehicleOwners.Items)
            {
                CheckBox checkBox = (CheckBox)item.FindControl("CheckBox");
                if (checkBox.Checked)
                {
                    Label label = (Label)item.FindControl("lblVName");
                   text=label.text;
                }

            }


The text will contain the value of that selected item.


Twitter Delicious Facebook Digg Favorites More