0
I’m tapping into the database and calling a procedure
to insert into the bank but this error occurs you know the reason:
Code:
Dim con As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
con = Nothing
cmd = Nothing
Try
con.ConnectionString = "Server = ;Database=;User Id=;Password = ;"
con.Open()
cmd.Connection = con
cmd = New SqlCommand("prdInserirRegistro", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@dtLog", SqlDbType.DateTime))
cmd.Parameters.Add(New SqlParameter("@dsLog", SqlDbType.VarChar, 1000))
'recebe o parâmetro selecionado na combobox
cmd.Parameters("@dtLog").Value = Now
cmd.Parameters("@dsLog").Value = txtBoxLog.Text
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("erro em: " & ex.Message)
Finally
If Not con Is Nothing Then
con.Close()
con.Dispose()
End If
con = Nothing
If Not cmd Is Nothing Then
cmd.Dispose()
End If
cmd = Nothing
What mistake happens?
– Asura Khan
On which line does the error occur? Where variables are declared
con
,conecta
,comando
,cmd
? Good names to cause trouble.– Maniero
this is the error :that occurs Object Reference not set to an instance of an Object the variables are declared above are like this: Dim con As Sqlconnection = New Sqlconnection() Dim cmd As Sqlcommand = New Sqlcommand() con = Nothing cmd = Nothing
– Renato Viturino