| |

VerySource

 Forgot password?
 Register
Search
View: 786|Reply: 6

Novice question: Which method should I use to read individual data? ?

[Copy link]

3

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-15 21:40:01
| Show all posts |Read mode
For example, I put some website information in a table, put one information in each field, and there is only one record in total

Excuse me, which of the following methods is better when reading? ? Or is there another way? ? Please advise

One:
datareader ["field"]. ToString ();

two:
dataset.Table ["tab"]. Rows [0] ["field"]
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-19 20:45:01
| Show all posts
datareader is more efficient.
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 United States

Post time: 2020-1-19 21:00:01
| Show all posts
If only one field is available
cmd.ExecuteScalar
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-19 22:36:02
| Show all posts
Of course the first is more efficient
Reply

Use magic Report

0

Threads

11

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-29 21:54:02
| Show all posts
If there is only one row in the table, why should we create a table? By design it fails. If you have to read, in theory, the reader is fast, but you only have the same, so it is the same, so there is no difference.
Reply

Use magic Report

0

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-3-14 01:15:01
| Show all posts
If you just read and do nothing else, it is recommended to use datareader.
Reply

Use magic Report

0

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-18 23:00:02
| Show all posts
Use the first datareader ["field"]. ToString ();
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list