| |

VerySource

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

How to change the name of a field in a dataset?

[Copy link]

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-5 16:40:02
| Show all posts |Read mode
Because you want to bind the names of the same field in two different tables to the same gridview at the same time, but there is a problem, because the field names are the same, an error is prompted, is there any way to change the field names of the tables in the dataset, or Two tables containing different data with the same fields are bound to the same dataset?

For example, both tables contain the two fields "ID", but the data is different. I want to generate a horizontal comparison by adding columns. That is, there are two tables with "ID" in a row. Can the name be changed? Want the data for the two "ID" columns to appear in the same row?

There is also a question, can you dynamically bind the datafield property of a column in the gridview, or can you dynamically bind a field in the dataset as required

thank you.
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-5 19:12:01
| Show all posts
Requires that the fields of the database cannot be changed. . . .
Reply

Use magic Report

0

Threads

21

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 United States

Post time: 2020-1-6 07:42:01
| Show all posts
Ask the landlord, how did you bind two different tables to the gridview at the same time?
As far as I know, if the gridview is directly bound to a dataset, the default is to bind dataset.tables (0) to this table.
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Netherlands

 Author| Post time: 2020-1-6 09:15:01
| Show all posts
Use the merge or Columns.Add method to merge into a table and then bind
Reply

Use magic Report

0

Threads

15

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 United States

Post time: 2020-1-6 11:54:01
| Show all posts
yourDataSet.Tables [0] .Columns [0] .ColumnName = "YourFieldName";
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-6 12:15:01
| Show all posts
1. change its name
ds.Tables [0] .Columns [0] .ColumnName = "NewFiled"

2. Or specify alias in sql


select A.ID AS ID1, B.ID ....
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-6 12:24:01
| Show all posts
There is also a question, can you dynamically bind the datafield property of a column in the gridview, or can you dynamically bind a field in the dataset as required
==========

can.

aspx. <% # GetString (Container.DataItem)%>

protected string GetString (object o)
    {
        DataRowView row = (DataRowView) o;
        return row ["field"]. ToString (); // This field can be specified according to conditions.
      
    }
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