Refer the below sample.
SQL
DECLARE @prsch AS TABLE(Entry_date DATETIME,code INT,name VARCHAR(20),net NUMERIC(18,5),IFSC VARCHAR(20),ACNO BIGINT)
INSERT INTO @prsch VALUES('03/03/2017',123,'Test 1',1500.5555,'SBIN0007084','11457290690')
select convert(varchar, Entry_date,103) as Entry_Date,code as SchoolCode ,name as SchoolName ,convert(Float,net) as Net,IFSC,ACNO from @prsch
Output
Entry_Date |
SchoolCode |
SchoolName |
Net |
IFSC |
ACNO |
3/3/2017 |
123 |
Test 1 |
1500.5555 |
SBIN0007084 |
11457290690 |
HTML
<asp:GridView ID="gvGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="SchoolName" HeaderStyle-HorizontalAlign="Center" HeaderText="School Name"
ItemStyle-HorizontalAlign="Left" ItemStyle-Width="100" />
<asp:BoundField DataField="SchoolCode" HeaderStyle-HorizontalAlign="Center" HeaderText="School Code"
ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100" />
<asp:BoundField DataField="Entry_date" HeaderStyle-HorizontalAlign="Center" HeaderText="Entry Date"
ItemStyle-HorizontalAlign="Left" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-Width="100" />
<asp:BoundField DataField="Net" HeaderStyle-HorizontalAlign="Center" HeaderText="Net"
DataFormatString="{0:n}" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100" />
<asp:BoundField DataField="ACNO" HeaderStyle-HorizontalAlign="Center" HeaderText="ACNO"
ItemStyle-HorizontalAlign="Right" ItemStyle-Width="150" />
<asp:BoundField DataField="IFSC" HeaderStyle-HorizontalAlign="Center" HeaderText="IFSC"
ItemStyle-HorizontalAlign="Left" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string query = @"DECLARE @prsch AS TABLE(Entry_date DATETIME,code INT,name VARCHAR(20),net NUMERIC(18,5),IFSC VARCHAR(20),ACNO BIGINT)
INSERT INTO @prsch VALUES('03/03/2017',123,'Test 1',1500.5555,'SBIN0007084','11457290690')
select convert(varchar, Entry_date,103) as Entry_Date,
code as SchoolCode ,name as SchoolName,convert(Float,net) as Net,IFSC,ACNO from @prsch ";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
SqlCommand cmd = new SqlCommand(query,con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
gvGrid.DataSource = dt;
gvGrid.DataBind();
}
}
Output
School Name | School Code | Entry Date | Net | ACNO | IFSC |
Test 1 |
123 |
03/03/2017 |
1,500.56 |
11457290690 |
SBIN0007084 |