Last post Jul 03, 2019 06:47 AM by samwu
Jul 02, 2019 03:34 PM|jsshivalik|LINK
In below code i want to display Data as only DatePart
txtDate.Text = sdr["PDate"].ToString();
Jul 03, 2019 05:40 AM|samwu|LINK
According to your description, I'm not quite clear about your requirements.
What's in SDR ["PDate"]？I need to know the specific contents of SDR ["PDate"].
Jul 03, 2019 06:06 AM|jsshivalik|LINK
using (SqlDataReader sdr = cmd.ExecuteReader())
Jul 03, 2019 06:47 AM|samwu|LINK
I mean I'd like to know the details of "PDate" in your database.Does it only save DateTime type of data and you want show this data in page. I suggest that you could convert its type to string.
Here's a demo you can use as a reference. In my database, I have a DateTime type of data.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
public string str = ConfigurationManager.ConnectionStrings["constr527"].ConnectionString;
string query = "select * from Date";
protected void Page_Load(object sender, EventArgs e)
using (SqlConnection con = new SqlConnection(str))
using (SqlCommand cmd = new SqlCommand(query,con))
SqlDataReader sdr = cmd.ExecuteReader();
string s1 = Convert.ToString(sdr["PDate"]);
DateTime.TryParse(s1, out value);
TextBox1.Text = value.ToString(("dd MMM yyyy"));