| |

VerySource

 Forgot password?
 Register
Search
View: 1325|Reply: 8

Does the data cannot be empty when reading data with iDataReader?

[Copy link]

2

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-4-22 16:00:01
| Show all posts |Read mode
I found some fields to appear when it comes: Data is Null. This Method or Property Cannot Be Called on Null Values.
Such an error! Don't know how you?
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2021-4-22 16:30:02
| Show all posts
You can also read it empty, put your code out..
Reply

Use magic Report

2

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2021-4-22 18:30:02
| Show all posts
Omployed part, there are a lot of code, and apply this part of the reading.

Using (iDataReader Rdr = db.executeReader (DBCommand, Transaction)
                {
                    While (Rdr.Read ())
                    {
                        Csinfo CS = New Csinfo (Rdr.GetInt32 (0), Rdr.getstring (1), Rdr.Getint32 (2));
                        CSS.Add (CS);
                    }
                }
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2021-4-22 22:45:01
| Show all posts
Is it because of the record you read, a field is empty, if it is empty, how can I "rdr.getint32 (0)."?
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2021-4-22 23:00:01
| Show all posts
Let's make a judgment, if it is empty, give a default value:

Try ..

            Csinfo cs = new csinfo ((Rdr.IsDBNULL (0))? 0: (Rdr.Getint32 (0)), (Rdr.Indbnull (1))? "" "": (Rdr.getstring (1)), (RDR. ISDBNULL (2))? 0: (Rdr.Getint32 (2)));
Reply

Use magic Report

2

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2021-4-22 23:15:01
| Show all posts
What is "a field is empty"? Thank you
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2021-4-22 23:45:01
| Show all posts
For example, a Student table, there are three fields (SNO, SNAME, SAGE)

One record

Sno Sname SAGE
111 NULL 21

IF (Rdr.Read ())
{
    IF (RDR.ISDBNULL (1))
    {
        // This record is not empty, but the SNAME field in the record is null ..
        // If there is an error with Rdr.getstring (1), because NULL cannot be converted to string ..
    }
}


I don't know if it is clear ..
Reply

Use magic Report

2

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2021-4-23 00:15:01
| Show all posts
Thank you, I understand.
Is there a better way to achieve this judgment? Because I have a lot of fields, this photo is too time.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-4-23 16:15:02
| Show all posts
The landlord does not read the value of iDataReader with rdr.getstring ().

For RDR [0] .toString ()
    Or column name RDR ["name"]. ToString () can read null values.
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