Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing NULL value ?????

Status
Not open for further replies.

keithinuk

Technical User
May 14, 2002
56
0
0
GB
Hello
I'm trying to store a null value in a column defined as Int32 with nulls allowed. I'm using SQL 2000 and VB.net.

NULL is not valid in .net so I've tried the following in my SQL
- System.DBNull.Value
- NullValue where NullValue is defined as
Public NullValue As System.DBNull = DBNull.Value

The SQL statement is constructed as follows in a public function with all datarefs passed to it.

Dim qs As New System.Text.StringBuilder("")
qs.Append("INSERT INTO opmember ")
qs.Append("(opmember_operation, opmember_workgroup, opmember_batched, ")
qs.Append("opmember_double_entry,opmember_confirm, opmember_stop_access, ")
qs.Append("opmember_account_access, opmember_isin_access, opmember_cheque_access) ")
qs.Append("VALUES(" & dataRef1)
qs.Append(", " & dataRef2)
qs.Append(", " & Quote & dataRef3 & Quote)
qs.Append(", " & Quote & dataRef4 & Quote)
qs.Append(", " & Quote & dataRef5 & Quote)
If dataRef6 = "" Then
qs.Append(", " & NullValue)
Else
qs.Append(", " & dataRef6)
End If
If dataRef7 = "" Then
qs.Append(", " & NullValue)
Else
qs.Append(", " & dataRef7)
End If
If dataRef8 = "" Then
qs.Append(", " & NullValue)
Else
qs.Append(", " & dataRef8)
End If
If dataRef9 = "" Then
qs.Append(", " & NullValue)
Else
qs.Append(", " & dataRef9)
End If

Any ideas please ?????????

Thanks
Keith In case I forget to say "Thank you" I'll say it now - thank you for your help !!!
 
Use the SQL null statement eg:

Code:
If dataRef6 = "" Then
   qs.Append(", NULL")
Else
   qs.Append(", " & dataRef6)
End If
--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top