Try vbNull, rather than DBNull.Value. On Fri, Apr 8, 2011 at 9:36 PM, Darron and Kerrie < dkpritch...@optusnet.com.au> wrote:
> I have just started programming in VB.net. > > I am recoding an old VB6.0 program to VB.net, and having a problem with > setting a database field back to null. > > The VB6.0 code was: > > Set rs = OpenTable("select * from tblunits where unit = " & "'" & temp & > "'") > rs!status = "Available" > rs!eventnum = Null > rs.Update > > I have tried a number of different way in VB.net but always get errors. > Here is my current code. > > > Dim > sqlda As New SqlDataAdapter > > Dim SQLcmd As New SqlCommand > > Dim TableFlag As DataTable > > Dim drunitstatus As DataRow > > With SQLcmd > > .Connection = conn > > .CommandType = > CommandType.Text > > .CommandText = ( > "select * from tblunits where unit = '" & UnitName & "'") > > End With > > sqlda = > New SqlDataAdapter(SQLcmd) > > TableFlag = > New DataTable > > sqlda.Fill(TableFlag) > > drunitstatus = TableFlag.Rows(0) > > drunitstatus("status") = "Available" > > drunitstatus("eventnum") = DBNull.value 'This appear to be the problem > line "eventnum" is int32 and allow nulls > > Dim > sCB As SqlCommandBuilder = New SqlCommandBuilder(sqlda) > > sqlda.Update(TableFlag) > > > > The Current error is "NullReferenceException was Caught" > > Can any one advise what I am doing wrong? > > Darron > > > > >