CheckBox value problem : Newsletter Module

Results 1 to 2 of 2

Thread: CheckBox value problem : Newsletter Module

  1. #1
    Join Date
    Dec 1969

    Default CheckBox value problem : Newsletter Module

    I am creating a newsletter module for administrator to send mails. In my access database, I have a field membergroupcode and it is integer data type. Depending on the member group, the newsletter will be sent. The administrator while creating the mail template will choose out of these groups by checking the checkbox of membergroups (represented by checkboxlist). How can I find out the checkboxes selected and what should be the access query to select all the members of the groups selected who have subscribed for the newsletter.<BR><BR>I was thinking of making the string of the checkboxes selected but then how do I compare this string with the integer type of field in database. like<BR><BR>select * from table where groupcode in (&#039;10,20,30&#039;)<BR><BR>but here groupcode is integer and it can not be compared with a string.<BR><BR><BR>Please help and also suggest if there is better way to find out the different groups.<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: CheckBox value problem : Newsletter Module

    In the query, technically since your entire query is a string variable (it will be compiled by the database driver) this is not an issue. Just make sure that the values are not in single quotes as this means it should be interpreted as a string value (23 = good, &#039;23&#039; = bad). Alternately, you can write the query using parameters:<BR><BR>OleDbCommand com; //if using a DataSet this will be (an OleDbCommand object)<BR><BR>com.CommandText="select * from [tablename] where groupcode in (?,?,?)"<BR>//the ?&#039;s are the parameters<BR>com.Parameters.Add ("param1", OleDbType.Integer);<BR>com.Parameters["param1"].Value=//the first groupcode<BR>//add the parameters in order of appearence<BR><BR>As for your CheckBoxes:<BR><BR>//make a CheckBoxList object<BR>CheckBoxList cbl //(this is a web server control, use this in the code behind function<BR><BR>//add your CheckBoxes to it either using its add function or by binding the control to some list of string elements by setting the cbl.DataSource= the table/ArrayList/etc. and setting cbl.DataTextField=a string containing the field (usually a column name) to display as the text of the CheckBox (e.g. if I want to display your groups, I&#039;d have a DataTable with a DataColumn by the name of "groups". I would set DataSource=the DataTable and DataTextField="groups", then call cbl.DataBind ();<BR><BR>get the values and make the query dynamically:<BR><BR>string query="select * from tablename where groupcode in (";<BR>for (int i=0;i&#060;cbl.Items.Count;i++) {<BR> if (cbl.Items[i].Selected) {<BR> query+="?,";<BR> command.Parameters.Add ("param"+i,OleDbType.Integer);<BR> command.Parameters["param"+i].Value=Convert.ToInt32<BR> (cbl.Items[i].Text);}}<BR>if (!query.EndsWith (")")) {<BR> query.Remove (query.Length-1,1);<BR> query+=")";}<BR>command.CommandText=query;<BR><BR> Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts