The birthday is a string inside my database and it is formatted like this Year/month/day
I want to calculate the age depending in the real time. For example, if the person was born on (2015/5/1) he should be age 1 year , and, depending in the date it can be 1 month , 1 year ,1 day, 7 year .. etc
I putted this mark /* to show where I want to convert the age
here This is my code but it won't help a lot
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Data.Odbc;
using System.Data.OleDb;
public partial class Reg : Page
{
protected void GO_Click(object sender, EventArgs e)
{
string myConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\db.mdb;Persist Security Info=True";
OleDbConnection myConnection;
OleDbCommand cmd;
try
{
// Open OleDb Connection
myConnection = new OleDbConnection();
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
// Execute Queries
cmd = myConnection.CreateCommand();
//---------------------------
int d = Convert.ToInt32(T7.Text);
int m = Convert.ToInt32(T6.Text);
int y = Convert.ToInt32(T5.Text);
string D = Convert.ToString(d);
string M = Convert.ToString(m);
string Y = Convert.ToString(y);
string n = T1.Text ,CID=T9.Text,FID=T8.Text;
string l = T2.Text;
string v = T4.Text,type= D1.SelectedItem.ToString();
string age = Y + "/" + M + "/" + D;
//---------------------------
cmd.CommandText = "SELECT count(*) FROM Visitor where CID ='" +CID + "' and FID ='" + FID + "'";
int temp ;
temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
Response.Write(temp);
if (temp == 1)
{
//getting the kid age
string kidAge= cmd.CommandText = "SELECT age FROME Visitor WHERE CID ='" + CID + "' and FID='" + FID + "' ";
// here my problem trying to conver kidAge to his real age maybe it 10year or something
/* DateTime today = DateTime.Today;
int Age = today.Year - kidAge.Year;
if (bday > today.AddYears(-age))
age--;
cmd.ExecuteNonQuery();
*/
// get the right vassile for kid depending in age it may be for 1 year ..etc
string Vassl = cmd.CommandText = "SELECT * FROM [Activating inoculation] where IID='"+ kidAge + "'";
cmd.ExecuteNonQuery();
// get nearst date for vassile
string AppDate = cmd.CommandText = "SELECT * FROM VassileAppointments where IID";
//updating
cmd.CommandText = "UPDATE Visitor SET Vphone ='" + v + "' where CID ='" + CID + "' and FID='" + FID + "' ";
cmd.ExecuteNonQuery();
// appointment
DateTime ReqDate = DateTime.Today;
cmd.CommandText = "INSERT INTO [Visitor Appointment] Type ='" + type + "', ReqDate ='"+ReqDate+"' ,AppointmentDate='" + AppDate + "' VID='" + CID + "'";
cmd.ExecuteNonQuery();
Response.Write(" تم تسجيل الموعد");
}
else
{
//works cmd INSERT cmd.CommandText = "INSERT INTO Visitor (FName,LName,age,Vphone) VALUES ('" + n + "','" + l + "','" + age + "','" + v + "')";
cmd.CommandText = "INSERT INTO Visitor (FName,LName,age,Vphone) VALUES ('" + n + "','" + l + "','" + age + "','" + v + "')";
cmd.ExecuteNonQuery();
Response.Write("تم تسجيل الموعد والبيانات");
}
}
catch (Exception ex)
{
Response.Write("OLEDB Connection FAILED: " + ex.Message);
}
}
}