Click here to Skip to main content
15,883,558 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

How to store the selected values of a group of check boxes in to database using asp.net (c#).

Eg: storing the hobbies selected by the user while registering, in to database.

--bdhkrl.
Posted
Comments
Sampath Lokuge 24-Apr-14 2:07am    
Can you put your code snippet ?
Thanks7872 24-Apr-14 2:11am    
That is what he is asking for...!
Sampath Lokuge 24-Apr-14 2:13am    
:)
Thanks7872 24-Apr-14 2:12am    
And whats the issue you are facing doing the same?

 
Share this answer
 
Comments
dontnetzone 24-Apr-14 8:31am    
hi Manoj,

I am using Mysql database.

Inserting into the table is successful, but the below code for retrieving the data has encountered one problem.

MysqlDataReader dr;

The above line is showing error "The type or namespace MysqlDataReader could not be found."

I have already done the reference part for Mysql.Data, still getting the issue.

What could be the problem.

Code below.



protected void Button2_Click(object sender, EventArgs e)
{

string connStr = "Server=localhost;Database=mysqldb;Uid=uid;Pwd=******$$;";
string intersts = "";

using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(connStr))
{

MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = conn;
// SqlCommand cmd = new SqlCommand("Select Interests from Demo", cn); // Write your Query i have taken as sample
cmd.CommandText = "Select areas from area_of_interests ";

MysqlDataReader dr;

//SqlDataReader dr;
conn.Open();

dr = cmd.ExecuteReader();
if (dr.Read())
{
intersts = dr["Interests"].ToString();
}
conn.Close();
string[] arr = intersts.Split(',');
foreach (ListItem item in this.CheckBoxList1.Items)
{
foreach (string s in arr)
{
if (item.Text == s)
{
item.Selected = true;
}
}
}

}
}

--
dotnetzone.
[no name] 30-Nov-14 23:31pm    
Clean, rebuild and add fresh reference..
no need to change any code...

still problem is there, please paste a detailed error here
hi Manoj,



The solution available in the above link suggested by you worked with Mysql DB also.

The MysqlDataReader issue was related to adding reference.

Thanks for the suggestion.


--dotnetzone.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900