Quantcast
Channel: update numeric field sql server gives 0 instead of "NULL" from gridview
Viewing all articles
Browse latest Browse all 2

update numeric field sql server gives 0 instead of "NULL" from gridview

$
0
0

Hi,

i have a gridview wich updates all rows in the grid, but the sql server database column is of a numeric type. the empty gridview cells get updated with the value "0" in the database instead of NULL. how can acomplish this. beneath is the update code: ( valueA is of type numeric in database)

Protected Sub Update(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click 

        For Each row As GridViewRow In GridViewexample.Rows

            If row.RowType = DataControlRowType.DataRow Then

                Dim cmd As New SqlCommand("UPDATE table set valueA = @valueA,valueB = @valueB WHERE ID='" + TxtboxID.Text + "' andvalueC=@valueC and valueD=@valueD andvalueE=@valueE and valueF=@valueF")

                cmd.Parameters.AddWithValue("@valueF", row.Cells(0).Controls.OfType(Of TextBox)().FirstOrDefault().Text)

                cmd.Parameters.AddWithValue("@valueE", row.Cells(2).Controls.OfType(Of TextBox)().FirstOrDefault().Text)

                cmd.Parameters.AddWithValue("@valueC", row.Cells(3).Controls.OfType(Of TextBox)().FirstOrDefault().Text)

                cmd.Parameters.AddWithValue("@valueD", row.Cells(4).Controls.OfType(Of TextBox)().FirstOrDefault().Text)

                cmd.Parameters.AddWithValue("@valueA", row.Cells(6).Controls.OfType(Of TextBox)().FirstOrDefault().Text)

                cmd.Parameters.AddWithValue("@valueB", row.Cells(7).Controls.OfType(Of TextBox)().FirstOrDefault().Text)

                'cmd.Parameters.AddWithValue("@valueF", GridViewonderzoeksresultaten.DataKeys(row.RowIndex).Value)

                Me.ExecuteQuery(cmd, "SELECT") 

            End If

        Next

        Me.BindGrid() 

    End Sub


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images