Hi alex0230,
Refer below code
Code
C#
protected void InsertDetails(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings("constr").ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Insert into tblWorkOrderSystemAdmin (Date) VALUES (@Date)"))
{
cmd.Connection = con;
if (!string.IsNullOrEmpty(txtScheduledDateForWork.Text.Trim()))
{
cmd.Parameters.AddWithValue("@Date", Convert.ToDateTime(txtScheduledDateForWork.Text.Trim()));
}
else
{
cmd.Parameters.AddWithValue("@Date", DBNull.Value);
}
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
VB.Net
Protected Sub InsertDetails(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("Insert into tblWorkOrderSystemAdmin (Date) VALUES (@Date)")
cmd.Connection = con
If Not String.IsNullOrEmpty(txtScheduledDateForWork.Text.Trim()) Then
cmd.Parameters.AddWithValue("@Date", Convert.ToDateTime(txtScheduledDateForWork.Text.Trim()))
Else
cmd.Parameters.AddWithValue("@Date", DBNull.Value)
End If
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Sub