Dipa Ahuja

Dipa Ahuja

  • NA
  • 3.1k
  • 715.4k

date format problem..

Feb 26 2010 9:43 AM

hi.. i am using birthdate field in createuserwizard control.. in my computer its working with fromat mm/dd/yyyy bt at collge same code raise error...
 
i have use compare validator for date type check..
<tr>
<%
-- Birthdate --%>
<
td align="right" style="width: 156px">
<asp:Label ID="lblbdate" Text="Birthdate(mm/dd/yyyy)" runat="server" AssociatedControlID="txtbdate"/></td><td>
<asp:TextBox runat="server" ID="txtbdate"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtbdate" ErrorMessage="Enter Birthdate" ValidationGroup="CreateUserWizard1" Text="*" />
<asp:CompareValidator ID="cmpbdate" runat="server" ControlToValidate="txtbdate" ErrorMessage="Invalid Date"Operator="DataTypeCheck" Text="#" Type="Date" Font-Size="Smaller"/>

</td></tr> <tr>
 
.cs
public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
//// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
p.Country = ((
DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Country")).SelectedValue;
p.Gender = ((
DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Gender")).SelectedValue;
p.FirstName = ((
TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtfname")).Text;
p.LastName = ((
TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtlname")).Text;
p.Email = ((
TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
p.BirthDate =
Convert.ToDateTime(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtbdate")).Text);
p.City = ((
TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("city")).Text;
p.PostCode = ((
TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtpcode")).Text;
p.uimage = ((
TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPictureURL")).Text;
//// Save the profile - must be done since we explicitly created this profile instance
 
 

da.Fill(ds,
"profile");
int count = ds.Tables[0].Rows.Count;
int pid = 0;
if (count > 0)
{
pid =
Convert.ToInt32(ds.Tables[0].Rows[count - 1][0].ToString());
pid = pid + 1;
}
else
{
pid = 1;
}
p.profile_Id = pid;
p.Save();
//adding data to profile....
TextBox uname=((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"));
string username = uname.Text;

objconnection.Open();
string c1 = "insert into profile(profileId,pimage,fname,lname,Username,Email,Sex,Birthdate,city_town,Country,Zip)values(@pid,@pimage,@fname,@lname,@uname,@Email,@sex,@bdate,@city,@country,@zip)";
SqlCommand comm = new SqlCommand(c1, objconnection);
comm.Parameters.AddWithValue(
"@pid", pid);
comm.Parameters.AddWithValue(
"@pimage", p.uimage.ToString());
comm.Parameters.AddWithValue(
"@fname", p.FirstName.ToString());
comm.Parameters.AddWithValue(
"@lname", p.LastName.ToString());
comm.Parameters.AddWithValue(
"@uname", username.ToString());
comm.Parameters.AddWithValue(
"@Email", p.Email.ToString());
comm.Parameters.AddWithValue(
"@sex", p.Gender.ToString());
Error @this line here:
comm.Parameters.AddWithValue(
"@bdate", Convert.ToDateTime(p.BirthDate.ToString()));
 

Answers (2)