try
{
string chkclassid1 = "";
if (chkclass.SelectedItem == null)
{
chkclassid1 = "0";
}
else
{
foreach (System.Web.UI.WebControls.ListItem item in chkclass.Items)
{
if (item.Selected == true)
if (chkclassid1 == "")
{
chkclassid1 = item.Value;
}
else
{
chkclassid1 = chkclassid1 + ", " + item.Value;
}
if (item.Selected)
{
chkclassid1 = item.Value;
SqlDataAdapter da = new SqlDataAdapter("select Residence_Phone_No from ApplicationForm where FK_Class =" + chkclassid1, con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
pno = Convert.ToInt32(ds.Tables[0].Rows[0]["Residence_Phone_No"]);
cmd = new SqlCommand("SP_InsertSms", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
DateTime createddate = System.DateTime.Now;
DateTime modfieddate = System.DateTime.Now;
//cmd.Parameters.AddWithValue("@Class_Id", chkclassid);
cmd.Parameters.AddWithValue("@Class_Id", chkclassid1);
cmd.Parameters.AddWithValue("@Phone_Number", pno);
cmd.Parameters.AddWithValue("@Message ", txtmessage.Text);
cmd.Parameters.AddWithValue("@Created_Date", createddate);
cmd.Parameters.AddWithValue("@Modified_Date", modfieddate);
cmd.Parameters.AddWithValue("@Created_User", user);
cmd.Parameters.AddWithValue("@Modified_User", user);
cmd.ExecuteNonQuery();
this.ClientScript.RegisterStartupScript(this.GetType(), "Message", "<script language=\"javaScript\">" + "alert('Record Inserted Succesfully...');" + "<" + "/script>");
clear();
}
}
}
}
}
I am writing this code for inserting records ,But the message is inserted for a single one,even though there are many records for the selected classes.where chkclass is id of check box
Structure of tables
Parent Parent_id,Class_id,Residence number
Message Message_id,Text Message,class_id
How to loop in dataset and insert multiple records.Help Me .It's very urgent
If there are 10 records for first and second message should be inserted for 20 records
vijaya