troubleshooting Question

Updating SQL server int field with gridview checkbox value

Avatar of jaytechnology
jaytechnologyFlag for Afghanistan asked on
ASP.NETMicrosoft SQL Server 2008.NET Programming
4 Comments1 Solution493 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
prajapati84

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros