|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Updating From Text BoxesHi, 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 Show quoteHide quote > 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 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 Show quoteHide quote "Brock Allen" wrote: > 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 > > > > > 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 > > > > How is what I suggested not disconnected data? SqlDataAdpater is just a layer
on SqlConnection and SqlCommand. -Brock DevelopMentor http://staff.develop.com/ballen Show quoteHide quote > 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 > "Brock Allen" wrote: > >> 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 >>> 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 Enrique..
Try glancing though this at:- http://www.solpart.com/techcorner/TCArticleViewer.aspx?Article=ADO.NET/e poch.xml Hope it helps Patrick *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Other interesting topics
web application security
unicode characters in web form aspx pages, utf-8 DataGrid Sort Expression for a date in format 'dd mmm yy' GAC and FileNotFoundException Can someone help? getting web page - control and class to talk to one another is hard... New Cracked Software(cad,cae,cam,eda,pcb,gis,cfd,cnc...) Runing Client-side code DataSet Disposal Control the size and position of a popup window. Losing state on bound controls in user controls |
|||||||||||||||||||||||