R
Reggie
Hi and TIA. I have a dataset that I fill from an Access table. Some
integer and date fields are null. I'm iterating through the records and
sending them to an SQL database table. The problem I'm having is I get an
error: (FormatException: Input string was not in a correct format.]) when it
comes to a null value in a field when I try placing it into the variable. I
have tried converting and everything I can't find a fix. Any advice on
where I can find the proper method would be appreciated. My code snippets
are below. I have my date variable declared as a string cause I was getting
an error when declared as a DateTime. Thanks for your time.
Dim intCVN_w_DMD As Integer
Dim intCVN_2Yr_Freq As Integer
Dim dtord_dttm As String
For Each row As DataRow In dst_MDB.Tables("1_NC_Analysis").Rows
intCVN_w_DMD = row("CVN_w_DMD").ToString 'here's where the error is
for null values
intCVN_2Yr_Freq = row("CVN_2Yr_Freq").ToString 'here's where the error
is for null values
dtord_dttm = row("ord_dttm").ToString 'here's where the error is for
null values
cmd = New SqlCommand("sp_NC_Analysis", con)
Try
With cmd
.CommandTimeout =
Convert.ToInt32(ConfigurationSettings.AppSettings("conTimeOut"))
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@CVN_w_DMD", SqlDbType.Int).Value = intCVN_w_DMD
.Parameters.Add("@CVN_2Yr_Freq", SqlDbType.Int).Value =
intCVN_2Yr_Freq
.Parameters.Add("@ord_dttm", SqlDbType.NVarChar).Value = dtord_dttm
End With
cmd.ExecuteNonQuery()
Catch sqlExc As SqlException
Label4.Text = sqlExc.ToString
End Try
integer and date fields are null. I'm iterating through the records and
sending them to an SQL database table. The problem I'm having is I get an
error: (FormatException: Input string was not in a correct format.]) when it
comes to a null value in a field when I try placing it into the variable. I
have tried converting and everything I can't find a fix. Any advice on
where I can find the proper method would be appreciated. My code snippets
are below. I have my date variable declared as a string cause I was getting
an error when declared as a DateTime. Thanks for your time.
Dim intCVN_w_DMD As Integer
Dim intCVN_2Yr_Freq As Integer
Dim dtord_dttm As String
For Each row As DataRow In dst_MDB.Tables("1_NC_Analysis").Rows
intCVN_w_DMD = row("CVN_w_DMD").ToString 'here's where the error is
for null values
intCVN_2Yr_Freq = row("CVN_2Yr_Freq").ToString 'here's where the error
is for null values
dtord_dttm = row("ord_dttm").ToString 'here's where the error is for
null values
cmd = New SqlCommand("sp_NC_Analysis", con)
Try
With cmd
.CommandTimeout =
Convert.ToInt32(ConfigurationSettings.AppSettings("conTimeOut"))
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@CVN_w_DMD", SqlDbType.Int).Value = intCVN_w_DMD
.Parameters.Add("@CVN_2Yr_Freq", SqlDbType.Int).Value =
intCVN_2Yr_Freq
.Parameters.Add("@ord_dttm", SqlDbType.NVarChar).Value = dtord_dttm
End With
cmd.ExecuteNonQuery()
Catch sqlExc As SqlException
Label4.Text = sqlExc.ToString
End Try