Illusionist Posted November 15, 2003 Posted November 15, 2003 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 Quote
Moderators Robby Posted November 15, 2003 Moderators Posted November 15, 2003 change this Event Time with this [Event Time] Quote Visit...Bassic Software
Illusionist Posted November 15, 2003 Author Posted November 15, 2003 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. Quote
techmanbd Posted November 15, 2003 Posted November 15, 2003 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, .... Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Illusionist Posted November 15, 2003 Author Posted November 15, 2003 In my Table i have: Name : Text UserID : Text Event : Memo Time : Date/Time : Format = General Date Cost : Currency tStamp : Date/Timer : Format = General Date Quote
Moderators Robby Posted November 15, 2003 Moderators Posted November 15, 2003 If you're using MS Access the surround dates with # instead of ' (single quotes) Quote Visit...Bassic Software
Illusionist Posted November 16, 2003 Author Posted November 16, 2003 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! Quote
Illusionist Posted November 16, 2003 Author Posted November 16, 2003 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! Quote
Moderators Robby Posted November 16, 2003 Moderators Posted November 16, 2003 So does the Insert work now? Quote Visit...Bassic Software
Illusionist Posted November 16, 2003 Author Posted November 16, 2003 Yes, Yes it does. Thanks for all your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.