Add days to current Date

Nov 2 2006 1:52 AM

I have created a table wherein the expiry date is calculated by adding no of days from a label besides the dropdown menu to the default date. Once a different item is selected the no of days will change  depending on the item.

I have written the code as follows:

string days;

DateTime dt = DateTime.Now;

SqlConnection con = new SqlConnection(ConnectionString);

SqlDataAdapter da = new SqlDataAdapter("select Valid_Days from Membership" ,con);

con.Open();

DataSet ds = new DataSet();

da.Fill(ds, "Membership");

DataTable dt = new DataTable();

dt = ds.Tables["Membership"];

DataRow[] dr = new DataRow[dt.Rows.Count];

dr = dt.Select();

if (dr.Length != 0)

{

days = dr[0]["Valid_Days"].ToString();

 

txtExpirydate.Text = dt.AddDays(days).ToString();

}

con.Close();


But I receive the following error :

Error 1 The best overloaded method match for 'System.DateTime.AddDays(double)' has some invalid arguments 

Error 2 Argument '1': cannot convert from 'string' to 'double' 

Please help 


Answers (2)