My Question is i have a checkboxlist component in my task .. the scenarios is I can click the Checkboxlist multiple meaning i can click the checkbox twice trice ... then after i click the button it will insert to Database.. how can i insert it to DB when
the checkbox is multiple? thank you.. i did already the for each but its not working this is my code...
ptitle = txtPtitle.Text
wstatus = rdbStatus.SelectedValue
wtype = cblType.SelectedValue categ = cblCategory.SelectedValue
expected_comp = rdpExpectedDate3.SelectedDate
'actual_comp = rdpExpectedDate3.SelectedDate
remarks_ = rtxtRemarks2.Text
Dim sql = "sp_Insertweeklyreport"
Dim dbcom As SqlCommand = New SqlCommand(sql, sqlcon123)
dbcom.CommandType = CommandType.StoredProcedure
dbcom.Parameters.AddWithValue("@createdBy", lblUname.Text)
dbcom.Parameters.AddWithValue("@pic", txtPIC.Text)
dbcom.Parameters.AddWithValue("@projectTitle", ptitle)
dbcom.Parameters.AddWithValue("@status_", wstatus)
dbcom.Parameters.AddWithValue("@expectedComp", expected_comp)
dbcom.Parameters.AddWithValue("@actualComp", DBNull.Value)
dbcom.Parameters.AddWithValue("@type_", wtype) dbcom.Parameters.AddWithValue("@category", categ)
dbcom.Parameters.AddWithValue("@recID_Main", 0)
dbcom.Parameters("@recID_Main").Direction = System.Data.ParameterDirection.Output
sqlcon123.Open()
dbcom.ExecuteNonQuery()
sqlcon123.Close()
Dim record_Main As String = Convert.ToInt32(dbcom.Parameters("@recID_Main").Value)
Dim spRemarks = "sp_InsertTblRemarks"
Dim dbcom1 As SqlCommand = New SqlCommand(spRemarks, sqlcon123)
dbcom1.CommandType = CommandType.StoredProcedure
dbcom1.Parameters.AddWithValue("@mainid", record_Main)
dbcom1.Parameters.AddWithValue("@createdby", lblUname.Text)
dbcom1.Parameters.AddWithValue("@remarks", remarks_)
dbcom1.Parameters.AddWithValue("@display", record_Main)
dbcom1.Parameters.AddWithValue("@RemarksID", 0)
dbcom1.Parameters("@RemarksID").Direction = System.Data.ParameterDirection.Output
sqlcon123.Open()
dbcom1.ExecuteNonQuery()
sqlcon123.Close()
I used stored procedure and asp.net for the environment ... thank you..
You need to loop through the checked values and then fire queries accordigly:
For i As Integer = 0 To chkContact.Items.Count - 1
Dim CheckBoxSelectedValue As Boolean = chkContact.Items(i).Selected
If CheckBoxSelectedValue = True Then
Dim CheckBoxValue As String = chkContact.Items(i).Value
Dim AddedDate As DateTime = System.DateTime.Now
Dim IsChecked As Boolean = True
objuser.InsertContactType(UserId, Convert.ToInt32(CheckBoxValue), AddedDate, IsChecked)
Else
Dim CheckBoxValue As String = chkContact.Items(i).Value
Dim AddedDate As DateTime = System.DateTime.Now
Dim IsChecked As Boolean = False
objuser.InsertContactType(UserId, Convert.ToInt32(CheckBoxValue), AddedDate, IsChecked)
End If
Next
aba123
0 Points
4 Posts
Checkbox list and DataBase
May 02, 2012 07:41 AM|LINK
Guys i need your help ..
My Question is i have a checkboxlist component in my task .. the scenarios is I can click the Checkboxlist multiple meaning i can click the checkbox twice trice ... then after i click the button it will insert to Database.. how can i insert it to DB when the checkbox is multiple? thank you.. i did already the for each but its not working this is my code...
ptitle = txtPtitle.Text wstatus = rdbStatus.SelectedValue wtype = cblType.SelectedValue categ = cblCategory.SelectedValue expected_comp = rdpExpectedDate3.SelectedDate 'actual_comp = rdpExpectedDate3.SelectedDate remarks_ = rtxtRemarks2.Text Dim sql = "sp_Insertweeklyreport" Dim dbcom As SqlCommand = New SqlCommand(sql, sqlcon123) dbcom.CommandType = CommandType.StoredProcedure dbcom.Parameters.AddWithValue("@createdBy", lblUname.Text) dbcom.Parameters.AddWithValue("@pic", txtPIC.Text) dbcom.Parameters.AddWithValue("@projectTitle", ptitle) dbcom.Parameters.AddWithValue("@status_", wstatus) dbcom.Parameters.AddWithValue("@expectedComp", expected_comp) dbcom.Parameters.AddWithValue("@actualComp", DBNull.Value) dbcom.Parameters.AddWithValue("@type_", wtype) dbcom.Parameters.AddWithValue("@category", categ) dbcom.Parameters.AddWithValue("@recID_Main", 0) dbcom.Parameters("@recID_Main").Direction = System.Data.ParameterDirection.Output sqlcon123.Open() dbcom.ExecuteNonQuery() sqlcon123.Close() Dim record_Main As String = Convert.ToInt32(dbcom.Parameters("@recID_Main").Value) Dim spRemarks = "sp_InsertTblRemarks" Dim dbcom1 As SqlCommand = New SqlCommand(spRemarks, sqlcon123) dbcom1.CommandType = CommandType.StoredProcedure dbcom1.Parameters.AddWithValue("@mainid", record_Main) dbcom1.Parameters.AddWithValue("@createdby", lblUname.Text) dbcom1.Parameters.AddWithValue("@remarks", remarks_) dbcom1.Parameters.AddWithValue("@display", record_Main) dbcom1.Parameters.AddWithValue("@RemarksID", 0) dbcom1.Parameters("@RemarksID").Direction = System.Data.ParameterDirection.Output sqlcon123.Open() dbcom1.ExecuteNonQuery() sqlcon123.Close() I used stored procedure and asp.net for the environment ... thank you..nijhawan.sau...
All-Star
16394 Points
3170 Posts
Re: Checkbox list and DataBase
May 02, 2012 08:16 AM|LINK
You need to loop through the checked values and then fire queries accordigly:
meeraacademy
Member
28 Points
9 Posts
Re: Checkbox list and DataBase
May 02, 2012 08:38 AM|LINK
I Think This Code is Little Difficult For Begineers,
So, Please Try This One Provided By
ASP.NET TUTORIAL, C#.NET TUTORIAL , PROJECT IN .NET, SQL SERVER by Meera Academy
Datatable DT = new DataTable
DT = LAdapter.Select();
if (DT.Rows.Count > 0)
{
chkfriend.DataSource = DT;
chkfriend.DataTextField = "name";
chkfriend.DataValueField = "ID";
chkfriend.DataBind();
}
Thakyou.