| |

VerySource

 Forgot password?
 Register
Search
View: 1372|Reply: 11

Ask a data set filling problem (white)

[Copy link]

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-7 15:30:01
| Show all posts |Read mode
protected void Page_Load (object sender, EventArgs e)
    {
        string sql = "select * from cheeck where shuihao = session ['shuihao']";
        SqlConnection con = new SqlConnection ();
        con.ConnectionString = "Server = i-server; database = fapiao; integrated security = SSPI;";
        con.Open ();
        SqlDataAdapter sqlda = new SqlDataAdapter (sql, con);
        DataSet ds = new DataSet ();
        
        DataTable mytable = ds.Tables ["cheeck"]

The above is a piece of my program. I would like to ask when filling the dataset object with FILL.
     Is the "cheeck" in sqlda.Fill (ds, "cheeck"); the result of the query using the select statement above? My cheeck is a table, and the error is displayed when running. I do n’t know how to fill the query content into ds Inside, ask ~
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-25 09:45:01
| Show all posts
string sql = "select * from cheeck where shuihao = session ['shuihao']";
        SqlConnection con = new SqlConnection ();
        con.ConnectionString = "Server = i-server; database = fapiao; integrated security = SSPI;";
        con.Open ();
        SqlDataAdapter sqlda = new SqlDataAdapter (sql, con);
        DataSet ds = new DataSet ();
sqlda.Fill (ds, "cheeck");
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-5-25 15:15:02
| Show all posts
"select * from cheeck where shuihao = session ['shuihao']";

=====>

 "select * from cheeck where shuihao = '" + session ["shuihao"]. ToString () + "'";
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-25 21:00:02
| Show all posts
Yes, it is to fill the results of the select statement query into ds, just follow the upstairs
sqlda.Fill (ds, "cheeck"); The cheeck in it is just an alias you take.
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-5-25 22:30:01
| Show all posts
I changed "select * from cheeck where shuihao = session ['shuihao']"; to
  
"select * from cheeck where shuihao = '" + session ["shuihao"]. ToString () + "'"; prompting an error saying "the name" session "does not exist in the current context" Is it defined before?
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-25 23:00:01
| Show all posts
This sentence is written as DataTable mytable = ds.Tables [0], just pull it!
Reply

Use magic Report

0

Threads

21

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-26 07:15:01
| Show all posts
session ["Sleep well"]. ToString ()

->

session ["Sleep well"]. ToString ()
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-5-26 08:00:01
| Show all posts
Oh, quietly ask, what does Tables [0] "0" in DataTable mytable = dsTables [0]. Mean,
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-5-26 16:30:02
| Show all posts
After I am modified according to the above suggestions, the runtime is directed to string sql = "select * from cheeck where shuihao = '" + Session ["shuihao"]. ToString () + "'"; this line prompts "The object reference is not set to "Instance of the object" error, how do I solve it?
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-26 17:15:01
| Show all posts
It is the first table in ds! default
The data set contains many tables
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