I'm rather new to this whole thing, so I may be doing something very wrong, but when I attempt to insert into an access database I get the following error (Line 21 is the problem line): Syntax error in INSERT INTO statement. Description: An unhandled exception
occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. Source
Error: Line 19: Line 20: Try Line 21: rowsAffected = dbCommand.ExecuteNonQuery Line 22: Finally Line 23: dbConnection.Close The source code for my insert statement is the following (generated by the ASP.NET WebMatcx Insert code builder): Function InsertLogInfo(ByVal
elTime As String, ByVal elEntryType As String, ByVal elDescription As String) As Integer Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=M:\Web\IDSite\I"& _ "ntrusionDetection.mdb" Dim dbConnection As System.Data.IDbConnection
= New System.Data.OleDb.OleDbConnection(connectionString) Dim queryString As String = "INSERT INTO [EventLog] ([elTime], [elEntryType], [elDescription]) VALUES ()" Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand dbCommand.CommandText
= queryString dbCommand.Connection = dbConnection Dim rowsAffected As Integer = 0 dbConnection.Open Try rowsAffected = dbCommand.ExecuteNonQuery Finally dbConnection.Close End Try Return rowsAffected End Function Can anyone help me??? -Joshua Yorktown, VA
I planned on having button click event handler insert data from a few text boxes on the page. Here's the event handler: Sub btnSubmit_Click(sender As Object, e As EventArgs) If Page.IsValid then InsertLogInfo(tbTime.Text, tbEntryType.Text, mbDescription.Text)
response.redirect("default.aspx") End Sub The values I suppose would be what's inside the InsertLogInfo() in the event handler. Are these values also supposed to appear in the VALUES () section of the INSERT statement??? The statement was generated by the
ASP.NET WebMatrix and there wasn't anything put in there. Hope this clears some stuff up. Thanks for the help. -Josh Yorktown, Va
u may try check ur String's value with this command Response.Write(queryString) c is there any value for ur string. from what i know, i nv use the [] in my sql statement b4, i wonder it may cause any error o not. can u tell me what is this command for? "Dim
dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString) " is it a object of OleDbConnection declaration...? it's looks weird to me. sorry, coz im just a newbie. i nv use this kind of declaration for OleDbconnection...
here is my example... dim Conn as new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;" &"Data Source=" & .....) ur connectionString is ok, but the system.data...... its abit weird... just keep on trying, u must not a newbie... best regards life's Ng
Code provided was produced by the Web Matrix INSERT statement builder. I'm thinking that the code builders that are in the program are producing very generic code becuase if the code worked it would work. The code that resulted didn't work. I'm not too sure
what to do next, but I think I'm going to get the ASP.NET Unleashed book to get into this a little deeper. Right now I'm reading ASP.NET in 24 Hours and it isn't very deep. I'll keep trying to tweak the code but in the meantime, thanks everyone for your input.
-Joshua, Yorktown, Va
Ho ho ho... something very important is missing from the *generated* code... it is the stuff inside the 'Values()' thing. You should try re-running the codebuilder and make sure that it generates some thing like: "INSERT INTO [EventLog] ([elTime], [elEntryType],
[elDescription]) VALUES (" & elTime & ... ")"
Ladies and gentlemen, I'm a complete bonehead. I re-read the book and when running the INSERT codebuilder, if you click on a column, you're essentially saying you don't want to do anything to that column...ie, not insert data into it. Man, I sure wish I read
everything in the beginning. Thanks to all of you you who suffered through this thread - and thanks to all who offered any kind of advice. I'll be sure to completely read the stuff first before asking dumb questions ;) Thanks again, Josh Oh yeah, I did get
the database to update.
joshis8up
Member
25 Points
5 Posts
Can't insert into Access db
Sep 12, 2003 05:04 AM|LINK
life's Ng
Contributor
2088 Points
432 Posts
Re: Can't insert into Access db
Sep 12, 2003 07:56 AM|LINK
joshis8up
Member
25 Points
5 Posts
Re: Can't insert into Access db
Sep 12, 2003 08:16 AM|LINK
life's Ng
Contributor
2088 Points
432 Posts
Re: Can't insert into Access db
Sep 12, 2003 09:40 AM|LINK
joshis8up
Member
25 Points
5 Posts
Re: Can't insert into Access db
Sep 15, 2003 04:21 AM|LINK
life's Ng
Contributor
2088 Points
432 Posts
Re: Can't insert into Access db
Sep 15, 2003 05:56 AM|LINK
salman_arsha...
Member
186 Points
38 Posts
Re: Can't insert into Access db
Sep 15, 2003 07:54 AM|LINK
joshis8up
Member
25 Points
5 Posts
Re: Can't insert into Access db
Sep 16, 2003 04:14 AM|LINK