This is a migrated thread and some comments may be shown as answers.

RadDatePicker database insert problem

2 Answers 108 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Arteta Sam
Top achievements
Rank 1
Arteta Sam asked on 20 Nov 2010, 12:28 PM
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 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 22 Nov 2010, 02:35 PM
Hello Nasri,

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

I hope that helps.
0
Arteta Sam
Top achievements
Rank 1
answered on 23 Nov 2010, 02:14 AM
Hi Cori,

Thank you for your reply...i found my mistake already.
Have a nice day!
Tags
Calendar
Asked by
Arteta Sam
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Arteta Sam
Top achievements
Rank 1
Share this question
or