read sql record into memory, use/modify fields then save changes

C

cj

How is the best way to return a single record via sql query that will
result in me being able to read and change the values of the individual
fields as needed as I proceed through a section of code?

Once this section of code is completed that record's changed will need
to be flushed back to the table it was pulled from. This process will
NOT involve a user interface.

I've written queries to get info for a datagrid before and I've written
queries to update records before but storing and reading/changing a
record then flushing it back is new to me in VB.

I'm using VB 2008.
 
Z

zacks

How is the best way to return a single record via sql query that will
result in me being able to read and change the values of the individual
fields as needed as I proceed through a section of code?

Once this section of code is completed that record's changed will need
to be flushed back to the table it was pulled from.  This process will
NOT involve a user interface.

I've written queries to get info for a datagrid before and I've written
queries to update records before but storing and reading/changing a
record then flushing it back is new to me in VB.

I'm using VB 2008.

SQLDataAdaptor maybe?
 
S

Steven Cheng [MSFT]

Hi Cj,

As for the data query & updating scenario you mentioned, is every query and
update only involve a single record? if so, I think you'd better use
SqlCommand with T-SQL statement to do the database query and updating. The
SqlCommand can execute select statement and return a DataReader, you can
get all the necessary column values out from the reader and them store them
into a in-memory class object for further usage.

Also, try using Parameters when you use SqlCommand to execute query:

#Use Parameters in your sql command
http://www.java2s.com/Code/VB/Database-ADO.net/UseParametersinyoursqlcommand
..htm

If there is any parituclar concerns or any questions about this, please
feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
 
C

Cor Ligthert[MVP]

cj,


A simple sqlConnection that has the Select statement and the connection
A simple datatable that you get with fill
A simple sqlCommandbuilder which you let get the information from that
\\\
dim cmd as new SqlCommandBuilder(yourdatadapter)
///
A a simple update with the same tableadapter with the changed row
And you are ready.


Another approach is creatinging an SQL Datareader with the same select
statement
To read one row
To create an SQL transact statement (which is mostly the most time consuming
in SQL transact code)
set all the parameters (the other bunch of work)
create an command (with the update command)
do an command.executenonquerry


A third approach probably most simple is
Create a datacontext (dbml)
Create a Linq statement to select the data
do a datacontext submitchanges

There are more

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top