| |

VerySource

 Forgot password?
 Register
Search
View: 1099|Reply: 10

Dear brothers, C # update database

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-26 16:40:01
| Show all posts |Read mode
I want to put DataSet wd = new DataSet ();
                sda.Fill (ds, "yfls");
The data is inserted into another table, but the ID column is not required. The ID in the inserted table is automatically generated.
Masters help.
Reply

Use magic Report

2

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-18 14:15:01
| Show all posts
this.dataGridView1.Columns.Remove ("ID"); // Remove ID column in DATAGRIDVIEW
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-19 16:45:01
| Show all posts
private void yflsDataBind ()
        {
            // conndata ();
            // SqlConnection con = new SqlConnection ("server = 192.168.23.212; database = databank; uid = sa; pwd = 123456");
            try
            {
                con.Open ();
                SqlDataAdapter yfwd = new SqlDataAdapter ("select yfdb.wendu as dbwd, yfzb.wendu as zbwd from yfdb, yfzb where yfdb.ID = yfzb.ID", con);
                DataSet wd = new DataSet ();
                yfwd.Fill (wd, "yfwd");
                // Binding data to the DataGridView
                // Requires receiving window creation. . .
                
                MyInvoke wdInvoke = new MyInvoke (yfwdBindDataGridView);
               
                this.BeginInvoke (wdInvoke, new object [] {wd});
            }
I take the data from the database, and then put it into another database, I want the data in yfwd, ds.Tables
["yfls"]. Rows [0] ["ID"]
["yfls"]. Rows [0] ["lasu"]
["yfls"]. Rows [0] ["wendu"]
["yfls"]. Rows [0] ["DateTime"]
Put into another table, the basic structure of the target is the same, but the ID column should be automatically generated instead of stored in the database.
 // SqlConnection con = new SqlConnection ("server = 192.168.35.115; database = LZdata; uid = sa; pwd = 123456");
// The database is different but the tables are the same, how to write next ---------------------------------- ----,
How should I save las, wendu, and DateTime of yfls to the yf table of LZdata as historical data? The ID of yfls is unchanged (he is an operation to update a row), so it cannot be inserted directly into the yf table. I can only ask for his last three columns
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-3-1 11:30:01
| Show all posts
In this case, if it is not troublesome, do a loop and insert it one by one ...
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-13 13:00:01
| Show all posts
Insert only one piece of data at a time, the key statements will not be written, beginners! !! !! !! Master help,
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-16 13:30:01
| Show all posts
Not using PB ?????
Reply

Use magic Report

0

Threads

31

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-3-16 20:30:01
| Show all posts
foreach (datarow oldrow in sourceDataSet.Tables [0] .Rows)
{
DataRow newRow = targetDataSet.Tables [0] .newRow ();
newRow ["columnname"] = oldrow ["columnname"];
.....
targetDataSet.Tables [0] .Rows.add (newRow);
}
Reply

Use magic Report

0

Threads

31

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-3-16 21:15:02
| Show all posts
In fact, it may be solved by a single SQL statement. I do n’t know the specific needs of the landlord.
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-17 07:30:01
| Show all posts
My question is on the third floor.
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-3-19 10:45:01
| Show all posts
I don't quite understand what the landlord means. If it is inserted one by one, is there any problem?

When building a table in the database, are there any self-incrementing columns in the table? Identity in sqlserver, sequence in oracle

For example, if there is a table student in sqlserver, and two fields sid and sname, if sid is self-incrementing ...

create table student (sid int identity (1,1), sname varchar (20));

insert:

insert into student (sname) values ​​('aaa');
insert into student (sname) values ​​('bbb');
...

The same is true in the program, you just need to get the columns other than the auto-increment column and insert it.


I wonder if I misunderstood what the landlord meant?
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