| |

VerySource

 Forgot password?
 Register
Search
View: 808|Reply: 8

Ask for help about database update `` ''

[Copy link]

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-5 10:10:01
| Show all posts |Read mode
The database that I bind in the GridView has 3 tables, and the relationship between the 3 tables is as follows:
的 The fields in student include student number, name, class number, and professional number;
The fields in the table class include class and class number;
The fields in the table zhuanye have professional, professional number;
However, the columns I bind in the GridView are: student number name class professional
Now I want to update records in the GridView, how should I write the update statement?
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-5 12:00:01
| Show all posts
Do you want to update three tables?
Reply

Use magic Report

0

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-5 12:03:01
| Show all posts
Two update statements, written in a transaction
Reply

Use magic Report

0

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-5 12:12:01
| Show all posts
I'm still writing programs during the holidays
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-5 12:27:01
| Show all posts
Yes
Otherwise it will have type conversion errors
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-5 12:30:01
| Show all posts
Update three tables, can only write three sql. Put in the transaction.

Note that the associated fields must be retrieved.
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 United States

 Author| Post time: 2020-1-5 13:12:01
| Show all posts
Can you write it for me?
I haven't written 3 in one transaction.
Reply

Use magic Report

0

Threads

25

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-1-5 14:24:01
| Show all posts
// establish a connection
            SqlConnection con = new SqlConnection ("server = .; database = student; uid = sa; pwd = 0421");
            // define a transaction
            SqlTransaction transaction = null;

            try
            {
                // Open the database connection
                con.Open ();
                // start transaction
                transaction = con.BeginTransaction ();
                // Insert command
                SqlCommand cmd1 = new SqlCommand ("insert into student values ​​('111', 'liujia')", con);
                SqlCommand cmd2 = new SqlCommand ("insert into class values ​​('111', 'liujia')", con);
                //carried out
                cmd1.ExecuteNonQuery ();
                cmd2.ExecuteNonQuery ();

                // Other operations, such as update
                // ........

                // All operations are completed, submit
                transaction.Commit ();
            }
            catch (Exception ex)
            {
                // roll back first
                transaction.Rollback ();
                // Exception handling below
                // ...
            }
            finally
            {
                // Close the database connection
                con.Close ();
            }
           
        }
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-5 19:24:01
| Show all posts
I am updating the database
The Update statement is used, so how to deal with the same fields of several 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