Hi pratikshir,
Refer below code and also refer below article link to insert record every day.
HTML
Date :<br />
<asp:TextBox runat="server" ID="txtLoginDate" /><br />
CompanyName :<br />
<asp:TextBox runat="server" ID="txtCompanyName" /><br />
<asp:Button Text="Update" runat="server" OnClick="Update" />
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Update(object sender, EventArgs e)
{
ChangeData(Convert.ToDateTime(txtLoginDate.Text), txtCompanyName.Text);
}
private void ChangeData(DateTime date, string companyName)
{
string password = companyName + "@" + DateTime.Now.ToString("ddMMyyyy");
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO UserChangePassword(date,companyName,password) VALUES(@date,@companyName,@password)", con))
{
if (date < DateTime.Today)
{
cmd.Parameters.AddWithValue("@date", date);
cmd.Parameters.AddWithValue("@companyName", companyName);
cmd.Parameters.AddWithValue("@password", password);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
VB.Net
Protected Sub Update(ByVal sender As Object, ByVal e As EventArgs)
ChangeData(Convert.ToDateTime(txtLoginDate.Text), txtCompanyName.Text)
End Sub
Private Sub ChangeData(ByVal date As DateTime, ByVal companyName As String)
Dim password As String = companyName & "@" & DateTime.Now.ToString("ddMMyyyy")
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("INSERT INTO UserChangePassword(date,companyName,password) VALUES(@date,@companyName,@password)", con)
If date < DateTime.Today Then
cmd.Parameters.AddWithValue("@date", date)
cmd.Parameters.AddWithValue("@companyName", companyName)
cmd.Parameters.AddWithValue("@password", password)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End If
End Using
End Using
End Sub