xmalcolm
asked on
String was not recognized as a valid Boolean.
Hi Guys,
I am getting the error String was not recognized as a valid Boolean. Currently what I am trying to do is save the user's preference on a profile.
This will allow me to run a query against the database and match the results to that of the person's preferences on the profile? I have attached my Web.Config file, aspx and aspx.cs files. Please help!!!!!
I am getting the error String was not recognized as a valid Boolean. Currently what I am trying to do is save the user's preference on a profile.
This will allow me to run a query against the database and match the results to that of the person's preferences on the profile? I have attached my Web.Config file, aspx and aspx.cs files. Please help!!!!!
Web Config File
<customErrors mode="Off"></customErrors>
<profile enabled="true" defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="SmokeP" type="boolean"/>
<add name="GenderP" type="boolean"/>
<add name="JourneyP" type="boolean"/>
</properties>
</profile>
ASPX File
<asp:Label ID="lblSmokeP" runat="server" Text="Select Smoking Preference" Font-Bold="true" Font-Size=8></asp:Label>
<asp:RadioButtonList ID="rbSmokeP" runat="server" Font-size="8">
<asp:ListItem>Smoker</asp:ListItem>
<asp:ListItem>Non-Smoker</asp:ListItem>
<asp:ListItem>Both</asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<asp:Label ID="lblGenderP" runat="server" Text="Select Gender Preference" Font-Bold="true" Font-Size=8></asp:Label>
<asp:RadioButtonList ID="rbGenderP" runat="server" Font-size="8">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
<asp:ListItem>Both</asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<asp:Label ID="lblJourneyP" runat="server" Text="Select Journey Preference (Seeking a Lift/Offering a Lift/Both)" Font-Bold="true" Font-Size=8></asp:Label>
<asp:RadioButtonList ID="rbJourneyP" runat="server" Font-size="8">
<asp:ListItem>Seeking</asp:ListItem>
<asp:ListItem>Offering</asp:ListItem>
<asp:ListItem>Both</asp:ListItem>
</asp:RadioButtonList>
ASPX.CS File
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = "Data Source=XG7;Initial Catalog=Car_Share_XG;Integrated Security=True";
myConn.Open();
SqlCommand command = new SqlCommand();
command.CommandText = "SELECT * FROM tbl_Member";
command.CommandType = CommandType.Text;
command.Connection = myConn;
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds, "tbl_Member");
// Get a FileStream object
StreamWriter xmlDoc = new StreamWriter(Server.MapPath("./Data2.xml"), false);
// WriteXml method to write an XML document
ds.WriteXml(xmlDoc);
xmlDoc.Close();
myConn.Close();
try
{
bool SmokeP = Profile.SmokeP;
if (SmokeP)
lblSmokeP.Text += " : Currently a Smoker";
else
lblSmokeP.Text += " : Currently a Non-Smoker";
}
catch
{
lblSmokeP.Text += " : Currently Both";
}
try
{
bool GenderP = Profile.GenderP;
}
catch
{
lblGenderP.Text += " Both";
}
try
{
bool JourneyP = Profile.JourneyP;
}
catch
{
lblJourneyP.Text += " Both";
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = "Data Source=XG7;Initial Catalog=Car_Share_XG;Integrated Security=True";
myConn.Open();
SqlCommand command = new SqlCommand();
command.CommandText = "SELECT Member_Address FROM tbl_Member";
command.CommandType = CommandType.Text;
command.Connection = myConn;
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds, "tbl_Member");
// Get a FileStream object
StreamWriter xmlDoc = new StreamWriter(Server.MapPath("./out1.xml"), false);
// WriteXml method to write an XML document
ds.WriteXml(xmlDoc);
xmlDoc.Close();
myConn.Close();
XmlDocument sourceDocument = new XmlDocument();
sourceDocument.Load(Server.MapPath("./out1.xml"));
XmlDocument outputDocument = new XmlDocument();
XmlElement markers = outputDocument.CreateElement("markers", "");
outputDocument.AppendChild(markers);
// use ChildNodes[1] if a <?xml version='1.0' encoding='utf-8'?> is in data2.xml, otherwise ChildNodes[0]
foreach (XmlNode node in sourceDocument.ChildNodes[0].ChildNodes)
{
XmlElement child = outputDocument.CreateElement("marker", "");
XmlAttribute att = outputDocument.CreateAttribute("address", "");
att.Value = node.ChildNodes[0].InnerText;
child.Attributes.Append(att);
markers.AppendChild(child);
}
outputDocument.Save(Server.MapPath("./out2.xml"));
Profile.SmokeP = Boolean.Parse(rbSmokeP.SelectedValue);
Profile.GenderP = Boolean.Parse(rbGenderP.SelectedValue);
Profile.JourneyP = Boolean.Parse(rbJourneyP.SelectedValue);
Profile.Save();
Response.Redirect("SearchPage2.aspx");
}
Try System.Boolean as property type
ASKER
where do I put that? on the top of the aspx page along with the other 'Using' commands?
Sorry, man. That won't help :(
ASKER
:(( any other ideas?
Check
rbSmokeP.SelectedValue
rbGenderP.SelectedValue
rbJourneyP.SelectedValue
What type of this controls? What exactly you are trying to parse?
rbSmokeP.SelectedValue
rbGenderP.SelectedValue
rbJourneyP.SelectedValue
What type of this controls? What exactly you are trying to parse?
ASKER
Well they are radio buttons. For example - for SmokeP - user can only select Smoker or Non-Smoker or Both
These values will then be used so that the query returns results matching the preference selected by the user.
These values will then be used so that the query returns results matching the preference selected by the user.
If they are asp:Radiobatton, then just use
Profile.SmokeP = RadioButton1.Checked;
Profile.SmokeP = RadioButton1.Checked;
In your case
Profile.SmokeP = rbSmokeP.Checked;
Profile.SmokeP = rbSmokeP.Checked;
ASKER
I Tried that earlier but I get a red underline. Could my web config be wrong?
<add name="SmokeP" type="boolean"/>
Profile.SmokeP = rbSmokeP.Checked;
When I hover over 'Checked' it says System.Web.UI.WebControls. RadioButto nList does not contain a definition for 'Checked' .....
<add name="SmokeP" type="boolean"/>
Profile.SmokeP = rbSmokeP.Checked;
When I hover over 'Checked' it says System.Web.UI.WebControls.
Profile.SmokeP = rbSmokeP.Selected;
Profile.SmokeP = (rbSmokeP.SelectedIndex = 1?True:False);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nope doesnt seem to work. It doesnt even come up on the list as soon as you put the dot after rbSmokeP. There is SelectedValue but then it shows this error: error CS0029: Cannot implicitly convert type 'string' to 'bool'. I then do it this way: Profile.SmokeP = Boolean.Parse(rbSmokeP.Sel ectedValue );
But get the error String was not recognized as a valid Boolean.
Please note: My radio buttons are 'RadioButtonList' instead of individual radio buttons with ID for each radio button.
But get the error String was not recognized as a valid Boolean.
Please note: My radio buttons are 'RadioButtonList' instead of individual radio buttons with ID for each radio button.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I believe that what you are looking for is this:
Profile.SmokeP = (rbSmokeP.SelectedItem.Tex t = "Smoker");
Profile.SmokeP = (rbSmokeP.SelectedItem.Tex
ASKER
Thanks the LearnedOne but Lazyberezovsky's solution worked or atleast i think its working :)). I am not getting an error message and my radio button stays selected on the preference I selected.
So thanks Lazyberezovsky. But now that I have done that, could you give me any ideas how I can use the stored preference to return results through a query. Currently I have:
SELECT Member_Address FROM tbl_Member
But what I need is SELECT Member_Address FROM tbl_Member WHERE (Preference selected is same as member preferences in tbl_member)
Any ideas?
So thanks Lazyberezovsky. But now that I have done that, could you give me any ideas how I can use the stored preference to return results through a query. Currently I have:
SELECT Member_Address FROM tbl_Member
But what I need is SELECT Member_Address FROM tbl_Member WHERE (Preference selected is same as member preferences in tbl_member)
Any ideas?