Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm working on a WebApplication for my school that will allow Students and Faculty to add events, respond tom, edit, etc.. But right now I'm just working on a standalone VB app to start with. I have a database and can read from it fine. Although when I try to insert into it, itgives me an error:

"A unhandled exception of type 'System.NullReferenceException' occured in DataBaseReadWrite.exe"

Additional information: Object reference not set to an instance of an object."

 

and it highlights my whole insert statement....

 

Take a look at it and see what you think:

DA.InsertCommand.CommandText = _
"INSERT INTO EventData (Name, " & _
"UserID, Event Time, Cost, tStamp)" & _ 
"VALUES('" & txtName.Text & "', " & _
"'" & txtUID.Text & "' , " & _ 
"'" & txtEvent.Text & "' , " & _
"'" & pckDateTime.Text "' , " & _
"'" & txtCost.text "' , " & _
"'" & Now.ToLongTimeString() & "')"

 

At first i was using it with SelectCommand.CommandText, and it worked when i inserted 3 values, and then i tried to add all of them int he SelectCommand and it gave me a syntax error in my INSERT INTO statement. Then i realized there was an InsertCommand (I'm very n00b at .net!) and I switched it , and now nothing works!

Any help will be greatly appreciated!

Thanks

Posted
Oops, that was a typo. There is supposed to be a comma between them. I'm actually doing this project on my laptop, and right now I'm on my desktop where I have internet at the moment. And I was just typing it on here, and mis-type on the postcode.
Posted

in the actual table are any of the fields set as a number? if they are then you don't need the ' ' around it.

 

you have this 'txtUID.Text' so part of the string looks like this

 

........ , '3', ................

should be like this ....... , 3, ....

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

Ok, i tried that, and now all I'm getting is a syntax error in my INSERT INTO statement.

In my Catch I have:

.....
Catch OleDB Exception as OleDb.OleDbException
   MsgBox("Error!" & vbCrLf & Err.Description)
   MsgBox(OleDbException.ErrorCode.ToString & vbCrLf & OleDbException.Source.ToString)
.....

And it returns:

Error!

Syntax Error in INSERT INTO statement.

and

-2147217900

Micosoft JET Database Engine

 

If anyone knows what this means, could you please help me out! Thank you!

Posted

I did some research on that error number and found two possible reasons:

1) I didn't have write permissions, or

2) One of my filed Names was a reserved word

 

I tried the first one first! I check my database to see if i did have write rights, and i did. So crossed that one out, and read about the 2nd possible cause.

I didn't know which of my feldnames was a reserved word, i was thinking it was Time, but jsut to be safe i put ([]) brackets around each of them, and it worked!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...