Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am develop one web application and write the code
C#
SqlConnection con = new SqlConnection("Data Source=NSYS1\\SQLEXPRESS;Initial Catalog=agfl;connect timeout=30;Integrated Security=True");
            con.Open();
            string strQuery = "select * from stf where rdate =@some";
            SqlCommand cmd = new SqlCommand(strQuery, con);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@some", TextBox6.Text);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            gvuser.DataSource = dt;
            gvuser.DataBind();
            con.Close();

but the date data can't be display in gridview what is problem of my code
Posted
v2
Comments
Siva Hyderabad 26-Oct-13 1:06am    
may be u dont take the datetime datatype for rdate column,
Raghavendra Guptha 26-Oct-13 3:05am    
I TAKEN ONLY DATE DATATYPE SO HOW TO CHANGE COLUMN TYPE SQLSERVER2008
Dharmesh Kanzariya 26-Oct-13 6:00am    
plz ,tell me in which format you want date...
may be you want in this format you want Date 26/10/2013 or else...?

then we go for the solution...
plz

SQL
select *,convert(varchar(10),rdate,103) as rdate1 from stf where rdate =@some

and in Grid view set rdate to rdate1 in source code
 
Share this answer
 
v3
Comments
Raghavendra Guptha 26-Oct-13 1:47am    
i am try this not working
C#
<asp:boundfield datafield="Your_Date_Column" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" xmlns:asp="#unknown" />


check it here
 
Share this answer
 
here appears all ok can show your source code
 
Share this answer
 
Comments
Raghavendra Guptha 26-Oct-13 3:12am    
SqlConnection con = new SqlConnection("Data Source=NSYS1\\SQLEXPRESS;Initial Catalog=agfl;connect timeout=30;Integrated Security=True");
con.Open();
string strQuery = "select * from stf where rdate =@some";
SqlCommand cmd = new SqlCommand(strQuery, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@some", TextBox6.Text);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
gvuser.DataSource = dt;
gvuser.DataBind();
con.Close();
Pls show ur aspx code of gridview...
 
Share this answer
 
Comments
Raghavendra Guptha 26-Oct-13 4:50am    
<asp:GridView ID="gvuser" runat="server" AutoGenerateColumns="False" PageSize="10"
Width="1017px" Caption="Settlement vouchers Feeding Details" AllowPaging="true"
>
<columns>
<asp:TemplateField HeaderText="S.No">
<itemtemplate>
<asp:Label ID="label1" Visible="true" runat="server" Text='<%# Eval("sno") %>'>


<asp:TemplateField HeaderText="RDATE">
<itemtemplate>
<asp:Label ID="label2" Visible="true" runat="server" Text='<%# Eval("rdate1") %>'>


<asp:TemplateField HeaderText="ACNO">
<itemtemplate>
<asp:Label ID="label3" Visible="true" runat="server" Text='<%# Eval("acno") %>'>


<asp:TemplateField HeaderText="NAME">
<itemtemplate>
<asp:Label ID="label4" Visible="true" runat="server" Text='<%# Eval("name") %>'>


<asp:TemplateField HeaderText="VNO">
<itemtemplate>
<asp:Label ID="label5" Visible="true" runat="server" Text='<%# Eval("vno") %>'>


<asp:TemplateField HeaderText="AMOUNT">
<itemtemplate>
<asp:Label ID="label6" Visible="true" runat="server" Text='<%# Eval("amt") %>'>


<asp:TemplateField HeaderText="EDATE">
<itemtemplate>
<asp:Label ID="label7" Visible="true" runat="server" Text='<%# Eval("edate") %>'>


<asp:TemplateField HeaderText="CHNO">
<itemtemplate>
<asp:Label ID="label8" Visible="true" runat="server" Text='<%# Eval("chno") %>'>



C For Code!!! 26-Oct-13 5:51am    
whats the exact column name of your date column in data table at one place you are using rdate and on another place it is edate which is causing problem.
please let me know ditto date column name as it is in your database table.
ErBhati 26-Oct-13 8:16am    
<asp:Label ID="label2" Visible="true" runat="server" Text='<%# Eval("rdate1") %>'>

check <%# Eval("rdate1") %> rdate1 is present in table or not...
Raghavendra Guptha 26-Oct-13 8:30am    
not in table rdate1
friend

if you want Date format like this '26/10/2013' in the grid then you have to change in your Query.

Like This...
string strQuery = "SELECT sno,CONVERT( varchar(10),rdate1,103)AS rdate1,acno,name,vno,amt,CONVERT( varchar(10),edate,103)AS edate,chno FROM stf Where convert(varchar(20),rdate1,103) = @some";

remaining code is as it is...

Any query regarding the format of date then asked ...

Hopefully, It is totally works....
Best of Luck....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900