Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2006, 04:23 AM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get Values from Checkboxlist

Hi, May I know how to insert the selected values from the checkboxlist into database? I having trouble to retrieve and store the selected value on the checkboxlist. How do i go about. Please help. Thanks

 
Old May 24th, 2006, 10:11 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Here's an example that gets the values that are checked. If its check it does a SELECT statement to see if that value is already in the database. If its not in the database, it inserts that value. In the else statement, which are values that are not checked it deletes that from the database.

Code:
For Each i As ListItem In cblFacilityAssign.Items
If i.Selected Then
Dim SQL As String = "SELECT * FROM [Table] WHERE [ID Column] = " & i.Value & ";"
Dim CMD As New SqlCommand(SQL, _oConn)
Dim oRS As SqlDataReader
oRS = CMD.ExecuteReader()
If Not oRS.Read() Then
oRS.Close()
Dim SQL2 As String = "INSERT INTO A[Table] ([Column1], [Column2], [Column3]) VALUES (" & [Value1] & ", " & [Value2] & ", " & i.Value);"
Dim CMD2 As New SqlCommand(SQL2, _oConn)
CMD2.ExecuteNonQuery()
Else
oRS.Close()
End If
Else
Dim SQL As String = "DELETE FROM [Table] WHERE [ID Column] = " & i.Value & ";"
Dim CMD As New SqlCommand(SQL, _oConn)
CMD.ExecuteNonQuery()
End If
Next
Hope this helps.

Richard

 
Old May 25th, 2006, 10:06 PM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks rstelma!


 
Old May 26th, 2006, 09:46 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

My pleasure.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkboxlist epkgupta Visual Studio 2005 0 March 11th, 2008 05:31 AM
CheckBoxList stu9820 ASP.NET 1.0 and 1.1 Basics 10 May 25th, 2006 08:15 PM
CheckBoxList and Null Values steve35719 ASP.NET 2.0 Basics 1 April 21st, 2006 09:42 AM
CheckBoxList eddiema VS.NET 2002/2003 1 April 9th, 2004 09:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.