RadDatePicker database insert problem

3 posts, 0 answers
  1. Arteta Sam
    Arteta Sam avatar
    31 posts
    Member since:
    Jan 2010

    Posted 20 Nov 2010 Link to this post

    Hi all,

    protected void btnSignUp_Click(object sender, EventArgs e)
            {
                try
                {
                    
                    string guid = System.Guid.NewGuid().ToString();
                    System.Guid g = new Guid(guid);
                    string txtName = (fvwSignUp.Row.FindControl("txtName") as TextBox).Text;
                    string txtEmail = (fvwSignUp.Row.FindControl("txtEmail") as TextBox).Text;
                    string txtPassword = (fvwSignUp.Row.FindControl("txtPassword") as TextBox).Text;
                    string rcbGender = (fvwSignUp.Row.FindControl("rcbGender") as RadComboBox).SelectedValue;
                   // DateTime rdpDate = (fvwSignUp.Row.FindControl("rdpDate") as RadDatePicker).SelectedDate;
             
                      
                    strConnection = ConfigurationManager.ConnectionStrings["pfms"].ConnectionString;
                    dbConn = new SqlConnection(strConnection);
                    dbConn.Open();
                    SqlCommand da = new SqlCommand("insert into SignUp values(@UserID,@UserName,@Email,@Password,@Gender,@BirthDate)", dbConn);
                   da.Parameters.Add("@UserID", SqlDbType.VarChar, 200).Value =guid;
                    da.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtName;
                    da.Parameters.Add("@Email", SqlDbType.VarChar).Value = txtEmail;
                    da.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtPassword;
                    da.Parameters.Add("@Gender", SqlDbType.Int).Value = rcbGender;
                    SqlParameter p1 = da.Parameters.Add("@BirthDate", SqlDbType.DateTime);
                    p1.Value = rdpDate.Value;
                   // DateTime dMyDate = rdpDate.Value;
      
                    da.ExecuteNonQuery();
                    fvwSignUp.ChangeMode(FormViewMode.ReadOnly);
                     
                }
      
                finally
                {
      
                    if (dbConn != null)
                    {
                        dbConn.Close();
                        bindData();
                    }
                }
     I have an error msg show that:-
    Error 5 The name 'rdpDate' does not exist in the current context 

    if i declare this radDatePicker, another error msg will display which is:-

    Error 5 'System.DateTime' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?) 


    Any help is appreciated....

    Best regards,
    Nasri
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 22 Nov 2010 Link to this post

    Hello Nasri,

    You have to declare rdpDate as DateTime?, not DateTime. As SelectedDate is nullable.

    I hope that helps.
  3. Arteta Sam
    Arteta Sam avatar
    31 posts
    Member since:
    Jan 2010

    Posted 22 Nov 2010 Link to this post

    Hi Cori,

    Thank you for your reply...i found my mistake already.
    Have a nice day!
Back to Top