Hi sambath,
Please refer below sample.
HTML
<div>
Date:
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
</div>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
Vb.Net
Imports System.Data.SqlClient
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select convert(varchar,BirthDate,101) AS BirthDate FROM Employees", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0]["BirthDate"] == DBNull.Value || dt.Rows[0]["BirthDate"].ToString() == "01/01/1900")
{
txtDate.Text = "";
}
else
{
txtDate.Text = dt.Rows[0]["BirthDate"].ToString();
}
}
}
}
}
Vb.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("select convert(varchar,BirthDate,101) AS BirthDate FROM Employees", con)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
If dt.Rows(0)("BirthDate") Is DBNull.Value OrElse dt.Rows(0)("BirthDate").ToString() = "01/01/1900" Then
txtDate.Text = ""
Else
txtDate.Text = dt.Rows(0)("BirthDate").ToString()
End If
End Using
End Using
End Using
End Sub
Screenshot