Dim myConnString As String = _
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Userpass.mdb;Jet OLEDB:Database Password=1234567890"
    Dim ds As New DataSet()
    Dim con As New OleDb.OleDbConnection(myConnString)
    Dim daCust As New OleDb.OleDbDataAdapter("Select * From Userpass1", con)
    Dim m_dtContacts As New DataTable
    Dim m_datarow As DataRow

    Dim m_cbCommandBuilder As OleDb.OleDbCommandBuilder
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'UserpassDataSet.Userpass1' table. You can move, or remove it, as needed.
        'Me.Userpass1TableAdapter.Fill(Me.UserpassDataSet.Userpass1)
        ComboBox1.SelectedIndex = 0
        ds.Clear()
        m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(daCust)
        'Uncomment either of the following two lines to obtain additional schema information.
        daCust.MissingSchemaAction = MissingSchemaAction.AddWithKey
        'daCust.FillSchema(ds, SchemaType.Source, "Cust")
        daCust.Fill(UserpassDataSet.Userpass1)
        'Userpass1DataGidView.DataSource = ds
        ' Userpass1DataGidView.DataMember = "123"
        'm_dtContacts.Columns("NewID").AutoIncrement = True
        'm_dtContacts.Columns("NewID").AutoIncrementSeed = 1

        ' m_dtContacts.PrimaryKey = 
        'con.Close()
        'con = Nothing
    End Sub
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If UserFound = False And PassFound = False Then
                m_datarow.BeginEdit()
                UserpassDataSet.Tables(0).Rows(0)!GroupID = "WA"
                m_datarow = m_dtContacts.NewRow
                m_datarow("UsersID") = RegName
                m_datarow("Keyword") = getMd5Hash((RegPass))
                m_datarow("GroupID") = ComboBox1.SelectedItem.ToString
                m_dtContacts.Rows.Add(m_datarow)
                ds.AcceptChanges()
                Try
                    Me.Validate()
                    m_datarow.EndEdit()
                    Dim ds2 As DataSet = UserpassDataSet.GetChanges()
                    'daCust.Update(UserpassDataSet.Userpass1)
                    daCust.Update(ds2, "Userpass1")
                    MsgBox("Update successful")
                    'daCust.Fill(ds2)
                Catch ex As Exception
                    MsgBox("Update failed" & ex.Message)
                End Try
 End If
End Sub

I try to fix these for 2days,searching solution all over the net, but with no luck:(. My Dataset just cannot be save into Database file, even every time message popup say it is sucessfull updated. Seem like i just updated my dataset and not Database. Is weird that even i stop debugging then rerun, the dataset seem updated, but i open my datafile everything is the same. My database is password protected, and the Datasource wizard dont allow me add the password in the connection string, so i need to do it manually.

Any help is highly appreciated(i have no clue aready),Maybe i try open new project n try@@Thanks in advance^^

Recommended Answers

All 3 Replies

Try to put absolute path of database and see what happens? (also remove acceptchanges() method).

Dim myConnString As String = _
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\xyz\Userpass.mdb;Jet OLEDB:Database Password=1234567890"

Wow!!!So many thanks:o Cant believe the solution is so easy, and I spend 2 days on it T.T Problem solve:)

But 1 weird thing happen,the primaryKey is ID(set by access as default),everytime i click button1, ID will increase by 2 instead of 1.
How can I set the PrimaryKey manually, I go trough the MSDN but cant get the idea.Any example, maybe I wan to change the Primarykey to UsersID. I stil not clear how primarykey work@@

Anyway,code can work...just a bit wierd:)

>I stil not clear how primarykey work

The main job of primary key is set a row (record) identity. So, you can delete /update a specific record using this identity.

>How can I set the PrimaryKey manually

create table sample(tno autoincrement(1,5) primary key , tname text(50))

Or

Right click on a column (in designer view), select "Primary Key" menu option.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.