Helloo......... how to set expiry date whenever my passport is expiry its automatically ALERT is there any code for expiration plz help me or give sum advice or sample

Dani AI

Generated

is right: keep the passport expiry as a date in the database and check it from your application. asked for details — since you said you use Visual Studio + SQL Server 2005, store expiry as a DATETIME (SQL 2005 has no DATE type), index that column, and run a simple query to find near‑term expiries. Don’t store dates as text.

Example schema and queries (SQL Server 2005):

CREATE TABLE Employees (
  EmployeeID INT IDENTITY(1,1) PRIMARY KEY,
  FullName NVARCHAR(200) NOT NULL,
  PassportExpiry DATETIME NULL
);

CREATE INDEX IX_Employees_PassportExpiry ON Employees(PassportExpiry);

-- passports expiring in the next 30 days
SELECT EmployeeID, FullName, PassportExpiry
FROM Employees
WHERE PassportExpiry BETWEEN GETDATE() AND DATEADD(day, 30, GETDATE());

-- already expired
SELECT EmployeeID, FullName, PassportExpiry
FROM Employees
WHERE PassportExpiry < GETDATE();

Sample VB.NET (ADO.NET) to build the alert text shown in your example ("MUNEEB passport will expire on 28-12-2011"):

Imports System.Data.SqlClient

Dim connString As String = "Data Source=SERVER;Initial Catalog=DB;Integrated Security=True;"
Dim daysAhead As Integer = 30
Dim sql As String = "SELECT FullName, PassportExpiry FROM Employees WHERE PassportExpiry BETWEEN GETDATE() AND DATEADD(day, @days, GETDATE())"

Using conn As New SqlConnection(connString)
  Using cmd As New SqlCommand(sql, conn)
    cmd.Parameters.Add("@days", SqlDbType.Int).Value = daysAhead
    conn.Open()
    Using rdr As SqlDataReader = cmd.ExecuteReader()
      While rdr.Read()
        Dim name As String = rdr("FullName").ToString()
        Dim expiry As DateTime = Convert.ToDateTime(rdr("PassportExpiry"))
        Dim message As String = String.Format("{0} passport will expire on {1}", name.ToUpperInvariant(), expiry.ToString("dd-MM-yyyy"))
        ' display, log or queue the message
      End While
    End Using
  End Using
End Using

Notes and tips: decide when to check — on user login, on a daily scheduled job, or via SQL Server Agent (sp_send_dbmail) or a Windows scheduled console app. Don’t run long background jobs inside an ASP.NET request. Consider timezone/date-only issues (store midnight or use UTC) and test with sample data. Use parameterized queries and index PassportExpiry for good performance.

Recommended Answers

All 7 Replies

what code you have so far? Please show some effort first. Thank you.

i dnt have any code..........jst i need advice / sample abt EXPIRY date how to set

Generally, if you are using a database the expiry date will be stored there. Without knowing more about what you want to achieve its hard to really help but, for example, if you were logging into a website and your password reset date was kept in the database, when you login code can check the current date vs the expiry date and alert you there is a week left, you're overdue, whatever.

if u have any code or sample plz can u snd me......................

muneeb213, don't ask for code if you don't even provide more information. Such as:
where do you save the expirydate (xml, sql database, access database, txt file???)
Also explain more detailed what EXACTLY you want to do.

ookk........i m using Visual studio & Sql Server 2005.............my all data save to sql database........

when employeee passport is expiry.......its display MUNEEB passport will expiry on 28-12-2011

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.