| |

VerySource

 Forgot password?
 Register
Search
View: 953|Reply: 5

What should I do if the UpData function of the database in VC prompts that the update fails? Which help

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-18 18:40:02
| Show all posts |Read mode
m_pSCSet-> Requery ();
while (! m_pSCSet-> IsEOF ())
{
if ((m_pSCSet-> m_grade <= 69)&&(m_pSCSet-> m_grade> = 60))
{
m_pSCSet-> m_grade + = 5;
m_pSCSet-> Update ();
m_pSCSet-> MoveNext ();
}
}
The title is to find tuples with scores between 60 and 69 in the table, and add 5 points to the score, but I use the above code to indicate that the update attempt failed
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-27 20:45:01
| Show all posts
Write directly with sql statement
Reply

Use magic Report

0

Threads

28

Posts

25.00

Credits

Newbie

Rank: 1

Credits
25.00

 China

Post time: 2020-8-27 21:00:01
| Show all posts
See what type of cursor of the recordset you opened, static cursors and read-only locks cannot be updated
If it's just an update, the first floor method is recommended
Reply

Use magic Report

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-8-27 21:15:01
| Show all posts
[Quote=Quote the post of the original poster继续跟随教主:]
m_pSCSet-> Requery();
while(!m_pSCSet-> IsEOF())
{
if((m_pSCSet-> m_grade <=69)&&(m_pSCSet-> m_grade> =60))
{
m_pSCSet-> m_grade += 5;
m_pSCSet-> Update();
m_pSCSet-> MoveNext();
}
}
The problem is to find the tuples in the table whose score is between 60 and 69, and add 5 points to the score, but I use the above code to indicate that the update attempt failed
[/Quote]

Use SQL directly

update tb
set fenshu = fenshu + 5
where fenshu between 60 and 69

It can also be like this.
declare @sql as varchar(100)
set @sql ='update tb set fenshu = fenshu + 5 where fenshu between 60 and 69'
exec(@sql)

You can put this SQL statement into your vc variable and execute it dynamically.
However, VC should not use exec, but use his own things.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-27 21:30:01
| Show all posts
1. As required by your code.. only need to update with SQl
2. Pay attention to the cursor of Ado.Recordset you opened to see if it is read-only
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-27 21:45:01
| Show all posts
CursorType cursor type
LockType Lock type

In addition, if you really need to make batch SQL updates in the program, you can use the open batch update mode... but it is not necessary as the title requires, it is too wasteful
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