Updating From Text Boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I apologize for a newbie question, but my books/research have yielded me
no examples and my time is now short.

I simply want to update data from text boxes (fields). I'm not using a
datagrid or datalist I found plenty of examples of how to do that and can get
that to work. I simply want to update my databound text boxes.
I'm using visual studios DataAdapters, DataSets and Dataviews. I can insert
to the database utilizing the sqladapter, but I can't figure out how to
update or delete using the records unique id / primary key.

Can someone please direct me to an example or show me sample code.
Preferrably in vb. I'm desperate. :)

Thanks,
enrique
 
So in your button click event you're going to have to write the SQL to do
an update back to your database:

Dim cn as new SqlConnection() ' this assumes you're using SqlServer
cn.ConnectionString = "some connection string (depends upon your DB and security
settings)"
cn.Open()
Dim cmd as SqlCOmmand = cn.CreateCommand()
cmd.CommandText = "update YourTable set x=@x, y=@y where z=@z"
cmd.Parameters.Add("@x", txtBoxX.Text)
cmd.Parameters.Add("@y", txtBoxY.Text)
cmd.Parameters.Add("@z", txtBoxZ.Text)
cmd.ExecuteNonQuery()
cmd.Dispose() ' technically we need to call Dispose(), as SqlCommand implements
IDisposable
cn.Close() ' Don't forget to close the connection

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Brock, Thank you very much.
Although I was looking for a solution that manipulates the disconnected data
and then updates via the sqlDataAdapter, this did the trick and I'm very
grateful.
I'll figure out updating dataTables and dataRows another day. (but if you
have the answer you can shoot it my way :) )

Again, Thanks!
-enrique
 
Back
Top