Avatar of jaytechnology
jaytechnology
Flag for Afghanistan asked on

Updating SQL server int field with gridview checkbox value

I am using VS 2010 .net4.  I have a grid view on my page that has a check box.  Once the user checks it, then submits the data,the check box clears.

Help please.
Thankyou
Dim myCommand As New SqlCommand("Insert into projectsHeader (ProjectName, StatusDate, StartDate, EndDate, PercentComplete, ProjectSponsor, ProjectManager, IRDirector, Status, ProjectOpen) Values (@pn, @sd, @std, @ed, @pc, @ps, @pm, @ird, @st, @po)", Conn)

        'find gridview variables
        Dim pn As TextBox = CType(gvProjects.FooterRow.FindControl("tbProjectName"), TextBox)
        Dim sd As TextBox = CType(gvProjects.FooterRow.FindControl("tbStatusDate"), TextBox)
        Dim std As TextBox = CType(gvProjects.FooterRow.FindControl("tbStartDate"), TextBox)
        Dim ed As TextBox = CType(gvProjects.FooterRow.FindControl("tbEndDate"), TextBox)
        Dim pc As TextBox = CType(gvProjects.FooterRow.FindControl("tbPercent"), TextBox)
        Dim ps As DropDownList = CType(gvProjects.FooterRow.FindControl("ddSponsor"), DropDownList)
        Dim pm As DropDownList = CType(gvProjects.FooterRow.FindControl("ddProjectManager"), DropDownList)
        Dim ird As DropDownList = CType(gvProjects.FooterRow.FindControl("ddDirector"), DropDownList)
        Dim st As DropDownList = CType(gvProjects.FooterRow.FindControl("ddStatus"), DropDownList)
        Dim po As CheckBox = DirectCast(gvProjects.FooterRow.FindControl("cbopen"), CheckBox)
        
        

       

        'set footer row for insert
        myCommand.Parameters.AddWithValue("@pn", SqlDbType.VarChar).Value = pn.Text
        myCommand.Parameters.AddWithValue("@sd", SqlDbType.Date).Value = sd.Text
        myCommand.Parameters.AddWithValue("@std", SqlDbType.Date).Value = std.Text
        myCommand.Parameters.AddWithValue("@ed", SqlDbType.Date).Value = ed.Text
        myCommand.Parameters.AddWithValue("@pc", SqlDbType.Decimal).Value = pc.Text
        myCommand.Parameters.AddWithValue("@ps", SqlDbType.VarChar).Value = ps.Text
        myCommand.Parameters.AddWithValue("@pm", SqlDbType.VarChar).Value = pm.Text
        myCommand.Parameters.AddWithValue("@ird", SqlDbType.VarChar).Value = ird.Text
        myCommand.Parameters.AddWithValue("@st", SqlDbType.VarChar).Value = st.Text
        myCommand.Parameters.AddWithValue("@po", SqlDbType.Bit).Value = po.Text
        

            'open connection
            Conn.Open()

            myCommand.ExecuteNonQuery()
            'close connection
            Conn.Close()

            'refresh the page
            Response.Redirect("NewProjectsDataEntry.aspx")

    End Sub

Open in new window

ASP.NETMicrosoft SQL Server 2008.NET Programming

Avatar of undefined
Last Comment
jaytechnology

8/22/2022 - Mon
Kevin Cross

For a CheckBox, I believe you want the Checked property and not Text.  What is likely happening is you are passing a string that doesn't evaluate to a boolean|bit and so is leaving the field as FALSE and as such the text box reverts to UnChecked.
Imran Javed Zia

Hi,
Use following
myCommand.Parameters.AddWithValue("@po", SqlDbType.Bit).Value = po.Checked

notice that you are using po.Text  

Thanks
ASKER CERTIFIED SOLUTION
prajapati84

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jaytechnology

ASKER
Thank you.  Had the int field.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23