1
Dim DOM As Nullable(Of Date) = IIf(String.Format("{0:dd/MMM/yyyy}", e.RowData("DOM")) = "", Nothing, String.Format("0:dd/MMM/yyyy}", e.RowData("DOM")))
cmd = New SqlCommand("inadditoninsert", CON)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@dom", SqlDbType.Date).Value =DOM
cmd.ExecuteNonQuery()
CON.Close()

Here i am not able to Pass the value of DOM in parameter @dom

Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40
  • did you declare @dom parameter in the stored procedure – PRABA Apr 12 '17 at 05:52
  • You need to include the code for procedure call and parameter initialization. – default locale Apr 12 '17 at 05:54
  • I have declared parameter @dom. The error shows that I have not supplied any value. I didn't selected any value and tried to pass NOTHING in that parameter. – Monika Rawat Apr 12 '17 at 05:56
  • Possible duplicate of [How can i pass a null value for date in vb.net to sql stored procedure?](http://stackoverflow.com/questions/649426/how-can-i-pass-a-null-value-for-date-in-vb-net-to-sql-stored-procedure) – default locale Apr 12 '17 at 05:59
  • kindly update your answer with stored procedure call and parameters also..check with New keyword also like: Dim nullableData As New Nullable(Of Date). – UsmanMirza Apr 12 '17 at 06:03
  • @MonikaRawat don't post your code in comment. please edit the question and paste your code. – PRABA Apr 12 '17 at 06:20
  • What is the exact error? You can pass a null to a parameter just fine. How are the parameters of the stored procedure defined? Your IIf statement performs an unnecessary conversion to string - if `e.RowData` returns null, why turn it into a string? Why not just assign that value to the property? – Panagiotis Kanavos Apr 12 '17 at 07:41
  • Possible duplicate of [Set a database value to null with a SqlCommand + parameters](http://stackoverflow.com/questions/170186/set-a-database-value-to-null-with-a-sqlcommand-parameters) – Panagiotis Kanavos Apr 12 '17 at 07:42
  • Have you tried setting the parameter value to `DBNull.Value` ? – Panagiotis Kanavos Apr 12 '17 at 07:43

1 Answers1

0
 Dim DOM As String = e.RowData("DOM")
 If DOM = "" Then
 cmd.Parameters.Add("@dom", SqlDbType.Date).Value = DBNull.Value
 Else
 cmd.Parameters.Add("@dom", SqlDbType.Date).Value = String.Format("{0:dd/MMM/yyyy}", e.RowData("DOM"))
 End If

Here is the solution to the problem.Thank You all of you for helping :)