| |

VerySource

 Forgot password?
 Register
Search
View: 771|Reply: 4

Ask a simple question

[Copy link]

2

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-30 11:20:01
| Show all posts |Read mode
SqlConnection conn = new SqlConnection ("server = localhost; Initial catalog = LIS; uid = sa; password =;");
            conn.Open ();
            SqlDataAdapter adapter = new SqlDataAdapter ("SELECT XM FROM BRXX WHERE ID =" + n, conn);
            SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
            
            DataSet ds = new DataSet ();
            
            string xm = Convert.ToString (ds.Tables ["BRXX"]. Rows [6] ["XM"]);

I want to get the XM value of the 6th row in the database. This is the wrong way to write it. It always contains the error "the object reference is not set to the object instance." Is there any other way to get a value in a row, or how do I do this? change?
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-3-6 20:00:01
| Show all posts
SqlConnection conn = new SqlConnection ("server = localhost; Initial catalog = LIS; uid = sa; password =;");
    SqlDataAdapter adapter = new SqlDataAdapter ("SELECT XM FROM BRXX WHERE ID =" + n, conn);
    DataSet ds = new DataSet ();
    adapter.Fill (ds, "BRXX");
    string xm = ds.Tables ["BRXX"]. Rows [5] ["XM"]. ToString ();
Reply

Use magic Report

1

Threads

18

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-6 21:00:02
| Show all posts
Write like this, there should be no data in ds,
Add adapter.Fill (ds, "BRXX"); try
Reply

Use magic Report

1

Threads

26

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-7 09:45:01
| Show all posts
You did not fill the data into the DataSet, of course, there will be errors, when Fill, the table structure and data are filled into the DS together! That would not be wrong!
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 Portugal

Post time: 2020-3-7 14:15:01
| Show all posts
Unpopulated dataset:
try ..

DataSet ds = new DataSet ();
adapter.Fill (ds, "BRXX");
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