Enter different number in database

knarim

New member
Joined
Jun 21, 2009
Messages
3
Programming Experience
Beginner
Hi!

It's looks like simple problem but I can't solve it. I would like to fill Access databse with one coloumn, just for test. When I connect to database and write number in textbox, confirm with the button it works well. I can see the number writen in the data table. But when I write another number in textbox and confirm with button the number writen in second row of data table is the same as first. So I cannot fill the datatable with different number throug textbox. any idea?

Here is the code thad gives me headacke:
VB.NET:
Private Sub vpisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vpisi.Click

        
        Try

            Integer.Parse(vnosnoPolje.Text)

        Catch ex As Exception

            MessageBox.Show("Torej" & " " & vnosnoPolje.Text & " " & "je za tebe število?")

        End Try

        If IsNumeric(vnosnoPolje.Text) = True Then

            vnosPod.Connection = baza

            vnosPod.CommandText = "INSERT INTO podatki (vhod) VALUES (@vhod)"

            vnosPod.Parameters.Add("@vhod", OleDbType.Integer).Value = CInt(vnosnoPolje.Text)

            baza.Open()
            vnosPod.ExecuteNonQuery()
            baza.Close()

            vnosnoPolje.Text = ""

            Me.PodatkiTableAdapter.Fill(Me.BazaDataSet.podatki)
            Me.BazaDataSet.AcceptChanges()

        End If

    End Sub


Thanks for answers!
 
1) See my answer in the other thread - you're creating an Insert command for no reason; the tableadapter already has one
2) If you add a new row to the datatable, and then call TableAdapter.Update() you get to a situation where your datatable and database contain the value, but a Fill() was not needed - it's an expensive op to keep downloading everything from a database all the time. Clever, no?
3) Read the DNU link in my signature
 

Latest posts

Back
Top