| |

VerySource

 Forgot password?
 Register
Search
View: 2341|Reply: 13

Can I use DataTable for SQL difference?

[Copy link]

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-26 12:40:01
| Show all posts |Read mode
public DataSet aaa (DataTable dt)
{
    string sql = "select a. *, b. * from tba left join" + dt + "b on a.id = b.id";
}
It doesn't work like this
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-16 21:00:02
| Show all posts
I can tell you responsibly: no
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-2-17 11:00:01
| Show all posts
I do n’t know. I want to achieve this effect. How should I do it?
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-5 02:00:01
| Show all posts
You can use DataTable.Name if you get the name of the DataTable consistent with the database, but the DataTable and the table in the database are not the same thing, it is best not to use this.
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-3-7 17:45:01
| Show all posts
What I want is to connect the DataTable to the Table in the database.
Wrong written above
 string sql = "select a. *, b. * from sqltb a left join" + dt + "b on a.id = b.id";

sqltb is the table in the database, dt is the DataTable difference
Reply

Use magic Report

0

Threads

13

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-8 19:45:01
| Show all posts
You can first fill the database table into the datatable
Combine these two datatables
Reply

Use magic Report

0

Threads

26

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-9 10:00:01
| Show all posts
Create a temporary table with the same name directly in the database, import the interface data into the temporary table and then join the query, but this is really stupid and the performance is super poor. The Merge effect of the DataSet is not very good, although the structure is merged, but the data It also turned up and was not easy to handle.
Or let's deal with the interface step by step with filtering.
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-3-9 16:00:01
| Show all posts
sqltb is a table in ms sql, DataTable is the number found from my sql, it is annoying to combine the two.
Reply

Use magic Report

0

Threads

26

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-10 00:15:01
| Show all posts
Since the DataTable is the number found from my sql, if there is no modification operation to the DataTable in the interface, you can rebuild the sql statement query in the form of a subquery, and use the result of the query number as the subtable of the new statement.

string sql = "select a. *, b. * from sqltb a left join (here is the sql statement for the number of queries) b on a.id = b.id";
Reply

Use magic Report

0

Threads

31

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-3-10 22:45:02
| Show all posts
as follows
If you set a name for DT

string sql = "select a. *, b. * from sqltb a left join" + dt.tablename + "b on a.id = b.id";
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