I am using Imports System.Data.SqlClient, which I assume means that my data handling is ADO.Net.
strCityType is a string but if the field is left blank I dont want anything for that field sent to the database. That is unless I can send something that will tell the database to keep the field a <NULL>. Because an empty string will not work for the application.
Off the top of my head the only thing I can think of to get around this is to have two different Insert Statements and then test for a value in the txtCityTax text box. If there is something in that box send the Insert Statement with the txtCityTax data. If not send the Insert Statement without the data included. For instrance:
It just seems like that is a horrible way to accomplish what I am trying to do. Is there an alternative?VB Code:
If txtcity.text = "" Then With cmd .CommandText = "Insert Into myTable (" & _ "Co, " & _ "BatchTransType" & _ ") Values(" & _ intCo & ", " & _ "'" & strBatchTransType & "')" .ExecuteNonQuery() End With Else With cmd .CommandText = "Insert Into myTable (" & _ "Co, " & _ "BatchTransType, " & _ "LocalCode" & _ ") Values(" & _ intCo & ", " & _ "'" & strBatchTransType & "', " & _ "'" & strCityTax & "'" & ")" .ExecuteNonQuery() End With End If




Reply With Quote