Question keeping records

mr.mham

New member
Joined
Jan 11, 2010
Messages
1
Programming Experience
1-3
hi all I'm new in vb.net and I would like to get some help in something

I'm developing a database application with vb 2008 and my database is MS access 2007 but every time I insert some records , they gone after a few moments . When I insert them I go to the database and I find them there but when I run the program for the second time I don't find them
this is the code
VB.NET:
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\smaa.accdb"
            Dim dbconnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
            Dim queryString As String = "INSERT INTO ncustomers (ID, custname , dat , sertype , amount , duration , paytype , phone , email) VALUES (" & txtid.Text & ", '" & txtname.Text & "' ,' " & txtdate.Text & " ', '" & txtst.Text & "' ,' " & txtamount.Text & " ', '" & txtdu.Text & "' ,' " & txtpt.Text & " ', '" & txtphone.Text & "' ,' " & txtemail.Text & " ');"
            Dim dbcommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbcommand.CommandText = queryString
            dbcommand.Connection = dbconnection
            dbconnection.Open()
            Dim rowsAffected As Integer = 0
            Try
                rowsAffected = dbcommand.ExecuteNonQuery
                MsgBox("Record Saved")
            Catch
                MsgBox("Record not saved")
            Finally
                dbconnection.Close()
                Me.Close()
            End Try
please any advice will be good
 
Last edited by a moderator:
To answer your specific question, follow the first link in my signature.

On a different note, you should avoid using string concatenation to build SQL statements. Follow the Blog link in my signature and check out my post on using parameters.
 
Back
Top