form data not being saved in access db

vailen

New member
Joined
Jul 17, 2009
Messages
2
Programming Experience
Beginner
hi

i'm using VS 2008 to design a windows application. I'm using ms access as my database but i'm having trouble saving form data into my database. I run this code and get no errors but no data is saved in the database table

Imports System.Data.OleDb
Imports System
Imports System.Data
Public Class HousingFrm

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

Dim conn As OleDbConnection
Dim comm As OleDbCommand
Dim sql As String

Try
sql = "INSERT INTO Housing(type, description, location) VALUES('" & typeTextBox.Text & "', '" & housingDescription.Text & "', '" & locationTextBox.Text & "')"
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\TMSDB.mdb;User ID=Admin;Password=")
conn.Open()

comm = New OleDbCommand(sql, conn)
comm.ExecuteNonQuery()

conn.Close()
comm.Dispose()
conn.Dispose()

MsgBox("Housing Information has been successfully saved. Thank you")
Catch ex As Exception

End Try



End Sub
 
Does it throw an Exception? If it was, you would be drowning it with the empty catch so maybe you missed it...

Otherwise, the most common error leading to the dataset's state not being updated to a file based database is the copy to output directory setting of the file. You must set it to "Copy if newer". You can get the properties of the file by doing a right click on the file in the solution explorer and clicking properties. This will bring up the properties of that file including the "copy to output directory". What happens if it is set to "Copy always" is that the old file replaces the new one everytime!

Btw, try using a typed dataset through the dataset designer. It will check your SQL queries to make sure they are syntactically correct so you can concentrate on other issues... There are plenty of ADO.NET tutorials for this, just google it :)
 
Read the DNU link in my signature
Then read the DW2 link in my signature, section Creating a Simple Data App
 

Latest posts

Back
Top