Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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 December 12th, 2006, 05:50 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default update database with checkbox

Hi, I am using a gridview with a templatefield containing a checkbox.
I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on another page)..i have been google around and found this....

If e.Row.RowType = DataControlRowType.DataRow Then

Dim Chk As CheckBox = e.Row.FindControl("CheckBox1")

just dont know what to do next...Any ideas?



__________________
www.nursery-net.com
 
Old December 12th, 2006, 07:10 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have been playing around with it and have this in my code behind..

Dim MyConnection As OdbcConnection

        MyConnection = New OdbcConnection() 'declare new connection object

        MyConnection.ConnectionString = "" 'database connect string

        MyConnection.Open() 'open connection to database

        Dim MyCommand As New OdbcCommand() 'declare new command object

        MyCommand.Connection = MyConnection

        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim Chk As CheckBox = e.Row.FindControl("save")
            If Chk.Checked = True Then
                MyCommand.CommandText = "update support.support set save = 1"

            End If

            If Chk.Checked = False Then
                MyCommand.CommandText = "update support.support set save = 0"

            End If

        End If

        MyCommand.ExecuteNonQuery()

        MyConnection.Close()

        MyCommand = Nothing

but when i run it i get this error....

ExecuteNonQuery: CommandText property has not been initialized

www.nursery-net.com




Similar Threads
Thread Thread Starter Forum Replies Last Post
update records in the database by checkbox Sakina Classic ASP Basics 2 September 9th, 2006 11:38 PM
checkbox update keyvanjan Classic ASP Basics 9 April 24th, 2006 10:10 PM
checkbox update keyvanjan Classic ASP Professional 1 April 18th, 2006 06:41 PM
Gridview Checkbox Update not updating using Access AUhawk ASP.NET 2.0 Basics 0 October 27th, 2005 01:30 AM





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