Make your columns' data type match to use UNION (ALL).
CAST(ItemId as VARCHAR(50)) as col1
Or
CONVERT(VARCHAR(50),ItemId) as colI1
DataSet MyQueryMethod(string sqlQueryString)
{
DataSet ds = new DataSet();System.Data.SqlClient.
SqlConnection sqlConnection = new System.Data.SqlClient. SqlConnection(System.System.Data.SqlClient.
SqlDataAdapter dataAdapter = new System.Data.SqlClient. SqlDataAdapter();System.Data.SqlClient.
SqlCommand select = new System.Data.SqlClient. SqlCommand(sqlQueryString);select.CommandType =
CommandType.StoredProcedure;select.Connection = sqlConnection;
select.Parameters.Add(
"@startdate", SqlDbType.DateTime).Value = TextBox1.Text;select.Parameters.
dataAdapter.SelectCommand = select;
dataAdapter.Fill(ds);
return ds;}
===========================================
on Load event for call the function
GridView1.DataSource = MyQueryMethod("BrowseUserCharge");
GridView1.DataBind();
The following examples show how to format float numbers to string in C#. You can use static method String.Format or instance methods double.ToString and float.ToString.
This example formats double to string with fixed number of decimal places. For two decimal places use pattern „0.00“. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded.
[C#]// just two decimal places
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
Next example formats double to string with floating number of decimal places. E.g. for maximal two decimal places use pattern „0.##“.
[C#]// max. two decimal places
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
String.Format("{0:0.##}", 123.0); // "123"
If you want a float number to have any minimal number of digits before decimal point use N-times zero before decimal point. E.g. pattern „00.0“ formats a float number to string with at least two digits before decimal point and one digit after that.
[C#]// at least two digits before decimal point
String.Format("{0:00.0}", 123.4567); // "123.5"
String.Format("{0:00.0}", 23.4567); // "23.5"
String.Format("{0:00.0}", 3.4567); // "03.5"
String.Format("{0:00.0}", -3.4567); // "-03.5"
To format double to string with use of thousands separator use zero and comma separator before an usual float formatting pattern, e.g. pattern „0,0.0“ formats the number to use thousands separators and to have one decimal place.
[C#]String.Format("{0:0,0.0}", 12345.67); // "12,345.7"
String.Format("{0:0,0}", 12345.67); // "12,346"
Float numbers between zero and one can be formatted in two ways, with or without leading zero before decimal point. To format number without a leading zero use # before point. For example „#.0“ formats number to have one decimal place and zero to N digits before decimal point (e.g. „.5“ or „123.5“).
Following code shows how can be formatted a zero (of double type).
[C#]String.Format("{0:0.0}", 0.0); // "0.0"
String.Format("{0:0.#}", 0.0); // "0"
String.Format("{0:#.0}", 0.0); // ".0"
String.Format("{0:#.#}", 0.0); // ""
To align float number to the right use comma „,“ option before the colon. Type comma followed by a number of spaces, e.g. „0,10:0.0“ (this can be used only in String.Format method, not in double.ToString method). To align numbers to the left use negative number of spaces.
[C#]String.Format("{0,10:0.0}", 123.4567); // " 123.5"
String.Format("{0,-10:0.0}", 123.4567); // "123.5 "
String.Format("{0,10:0.0}", -123.4567); // " -123.5"
String.Format("{0,-10:0.0}", -123.4567); // "-123.5 "
If you need to use custom format for negative float numbers or zero, use semicolon separator „;“ to split pattern to three sections. The first section formats positive numbers, the second section formats negative numbers and the third section formats zero. If you omit the last section, zero will be formatted using the first section.
[C#]String.Format("{0:0.00;minus 0.00;zero}", 123.4567); // "123.46"
String.Format("{0:0.00;minus 0.00;zero}", -123.4567); // "minus 123.46"
String.Format("{0:0.00;minus 0.00;zero}", 0.0); // "zero"
As you could notice in the previous example, you can put any text into formatting pattern, e.g. before an usual pattern „my text 0.0“. You can even put any text between the zeroes, e.g. „0aaa.bbb0“.
[C#]String.Format("{0:my number is 0.0}", 12.3); // "my number is 12.3"
String.Format("{0:0aaa.bbb0}", 12.3); // "12aaa.bbb3"

SELECT EmployeeId, EmployeeName, Salary
FROM Employees
EmployeeId EmployeeName Salary
-------------------------------------
1002 Alden 4000
2343 Lawson 4500
2004 Barbra 4800
1105 Marsden 4500
3116 Mac 5000
SELECT ROW_NUMBER()
OVER (ORDER BY EmployeeName) AS Row,
EmployeeId, EmployeeName, Salary
FROM Employees
Row EmployeeId EmployeeName Salary
-------------------------------------------
1 1002 Alden 4000
2 2343 Lawson 4500
3 2004 Barbra 4800
4 1105 Marsden 4500
5 3116 Mac 5000
Using ROW_NUMBER() for calculating Nth highest salary
We can utilize this function for calculating Nth highest salary of a employee. Suppose we want to find employee with 4th highest salary. This can be done as:SELECT * FROM
(SELECT ROW_NUMBER()
OVER (ORDER BY Salary) AS Row,
EmployeeId, EmployeeName, Salary
FROM Employees) AS EMP
WHERE Row = 4
Row EmployeeId EmployeeName Salary
-------------------------------------------
4 1105 Marsden 4500
Using ROW_NUMBER() in case of pagination
This can also be used for getting rows which belongs to a particular page only. This is very common scenario of a business application where we have lots of rows in database and we want to filter based on page number.SELECT * FROM
(SELECT ROW_NUMBER()
OVER (ORDER BY EmployeeName) AS Row,
EmployeeId, EmployeeName, Salary
FROM Employees) AS EMP
WHERE Row BETWEEN 2 AND 4
Row EmployeeId EmployeeName Salary
-------------------------------------------
2 2343 Lawson 4500
3 2004 Barbra 4800
4 1105 Marsden 4500
happy programming :D