PDA

View Full Version : INSERT Statement nightmare



eckertc
12-09-2006, 08:06 PM
Hey All,

Im using MS Visual Web Developer with an Access Database, i am trying to enter a new row of data into a database via a select statment attached to a button_click event. the code i am using looks something like this.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.AccessDataSource2.SelectCommand = "INSERT INTO [Tblissues] ([IssueDate], [IssueTime], [PlantLocation], [MachineName]) VALUES ('12/9/06', '3:00 PM', 'Gville', 'Snack2')"

End Sub


that being said. when i click the button, NOTHING happens, no error and no insert!!!


I did test the connection to the Database and its fine, i can do an update and i can read the data that exists in the database i just cant insert a new row.

This is not the first time i have delt with INSERT statments but this has me at my whits end and any help would be great.

Thanks

eckertc
12-09-2006, 09:41 PM
For those interested i answered my own question. the problem was that i was creating the INSERT statement but never executing it DUH!!.

Here is the updated code that works:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sqlinsert
sqlinsert = "INSERT INTO [Tblissues] ([IssueDate], [IssueTime], [PlantLocation], [MachineName]) VALUES ('12/9/06', '3:00 PM', 'Gville', 'Snack2')"

Try
Me.AccessDataSource2.InsertCommand = sqlinsert
Me.AccessDataSource2.Insert()
Catch Ex As Exception
MsgBox(Ex.ToString)
End Try

End Sub

Thanks anyway, and maybe this post will help someone in the future.