I have a rather large web app that I'm trying to debug and I get this error on multiple pages:
---------------------
Object reference not set to an instance of an object.
---------------------
The error is pointing at my insert statement but there is nothing wrong with the statement. I've also checked to make sure that each field in the web app has a place in the insert statement, verified the names in the DB with the names in the insert statement and made sure that the values in the insert statement are correct with the names in the SQL placeholders (@dotnet.itags.org.variable).
I don't understand this error. Any ideas?
DaleThe error is actually with your .NET code. On your command, I can place a bet that it is nulled/nothing. You must create a new instance of the command. For example:
SqlCommand command = null; // you must have something like this...
// but this is correct
SqlCommand command =new SqlCommand();
Okay. So if I have it setup as in the following:
Dim DBConnect As New SqlConnection
Dim InsertStatement As New SqlCommandDBConnect.ConnectionString = ("server=SERVER;database=DATABASE;uid=SA;password=PASSWORD")
InsertStatement.CommandText = "Insert TABLE (Column1, Column2) & _
"Values (@.Column1, @.Column2)"InsertStatement.Parameters.Add("@.Column1", SqlDatatype, Char, 30).Values=txtColumn1.Text
InsertStatement.Parameters.Add("@.Column2", SqlDatatype, Char, 30).Values=txtColumn2.Text
...
Where/how do I add the "SqlCommand Command = New SqlCommand()"?
Thanks again,
Dale
That code was in C#... you are coding in VB.NET. You have the equivelence over here -- so which line is giving you the problem?
Well, it is specifying the acutal insert statement as the pint of failure.
(** In my last post I fogot to type the " at the end of the statement, I've corrected this below.)
InsertStatement.CommandText = "Insert TABLE (Column1, Column2)" & _
So you typed this online then? If you have then you have just found a "silly" typing error. In your original code, you might have this:
Dim InsertStatement As SqlCommand ' notice the "new" missing
However you must create a new instance of the InsertCommand variable. You have done this in the above post but you could have overread your original code. It should be creating a new instance like here:
Dim InsertStatement As New SqlCommand
Not a problem Dale.
Yes, if fact I just added that to my code to see if that was the issue. check back to see if it worked. Thanks a TON!
Dale
0 comments:
Post a Comment