Writing to database

bharanidharanit

Well-known member
Joined
Dec 8, 2008
Messages
53
Location
India
Programming Experience
1-3
Hello,
I am using OLEDB and using datareader and with the read function i am reading table to the form.
But now i want the textbox values to be written to the table???
I tried with the fill, but not getting.
 
Hello,
I am using OLEDB and using datareader and with the read function i am reading table to the form.
But now i want the textbox values to be written to the table???
I tried with the fill, but not getting.

Do yourself a favour, dump everything you have written and start again, using the advice you find in the DW2 link in my signature. Read the section "Creating a Simple Data App"
 
Private Sub write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles write.Click

b = st2.Text.ToString

myConnection.Connection = povezava
myConnection.CommandText = "INSERT INTO rezultat (stevilo2) VALUES (@stevilo2)"
vpisi2.Parameters.Add("@stevilo2", OleDbType.Integer).Value = b

povezava.Open()
vpisi2.ExecuteNonQuery()
povezava.Close()

'Koda za ki omogoča spremljanje dogajanja v tabeli
Me.RezultatTableAdapter.Fill(Me.ZbirkaDataSet.rezultat)
Me.ZbirkaDataSet.AcceptChanges()

End Sub


I hope it will help, but problem is that only first number is always writen in the data table
 
...
myConnection.CommandText = "INSERT INTO rezultat (stevilo2) VALUES (@stevilo2)"
...
Me.RezultatTableAdapter.Fill(Me.ZbirkaDataSet.rezultat)
Me.ZbirkaDataSet.AcceptChanges()

Why would you declare, create and populate a parameterized command to insert into a table when there is already a tableadapter there with fully popualted insert command that will do the job for you?

Me.RezultatTableAdapter.Insert(b)

That's all that was needed
 
Back
Top