Home All Groups Group Topic Archive Search About

Updating From Text Boxes

Author
22 Mar 2005 11:39 PM
enrique
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

Author
23 Mar 2005 1:03 AM
Brock Allen
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
Are all your drivers up to date? click for free checkup

Author
23 Mar 2005 3:57 AM
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
>
>
>
>
Author
23 Mar 2005 4:16 AM
Brock Allen
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
Author
23 Mar 2005 5:56 AM
Patrick Olurotimi Ige
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!

Bookmark and Share