| |

VerySource

 Forgot password?
 Register
Search
View: 931|Reply: 7

Why did I add an error? ? ?

[Copy link]

3

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-11 09:00:02
| Show all posts |Read mode
I use vb.net connection to update the Access database. The data types of textbox4 and textbox5 are both numbers, and the others are text. When adding records, as long as the data type added is correct, you can continue to add records, but once the data type added is wrong, an error warning pops up even if the data type of the records added later is correct, why is this so? Which expert can help my little brother? Thanks in advance! Here is my code: Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim SQL As String
        Dim addItem As OleDb.OleDbCommand
        Try
            SQL = "INSERT INTO message VALUES (" + Chr (39) + CStr (TextBox5.Text) + Chr (39) + "," + Chr (39) + CStr (TextBox1.Text) + Chr (39) + ", "+ Chr (39) + CStr (TextBox2.Text) + Chr (39) +", "+ Chr (39) + CStr (TextBox3.Text) + Chr (39) +", "+ Chr (39) + CStr (TextBox4.Text) + Chr (39) + ")"
            'Chr (39) in the above formula stands for single quote, because the ASCII code for single quote is 39. So Chr (39) can also be replaced with "'", because the format of the INSERT statement is: INSERT INTO table name (field 1, field 2, field 3 ...) VALUES (' value 1 ',' value 2 ',' value 3 '...)
            OleDbConnection1.Open ()
            addItem = New OleDb.OleDbCommand (SQL, OleDbConnection1)
            addItem.ExecuteNonQuery ()
            OleDbConnection1.Close ()
            DataSet11.Clear ()
            OleDbDataAdapter1.Fill (DataSet11, "message")
            xianshi ()
        Catch ex As Exception
            MessageBox.Show ("Wrong type! Please verify!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
    End Sub
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-15 14:36:01
| Show all posts
Set a breakpoint, debug it yourself, and jump to Catch when you see which sentence is run
Reply

Use magic Report

0

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-16 09:36:01
| Show all posts
INSERT INTO message

change

INSERT message
Reply

Use magic Report

1

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-16 13:36:01
| Show all posts
What is the field type?
You can do data verification before joining the database, and then add
if is IsNumeric ("") then 'is a number
    'Broadcast data
else
   'Error prompt, exit
end if
Reply

Use magic Report

0

Threads

3

Posts

1.00

Credits

Newbie

Rank: 1

Credits
1.00

 China

Post time: 2020-1-16 15:56:06
| Show all posts
Because after you made an error, OleDbConnection1 is not closed? The next time you open it, it will jump abnormally.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-17 09:36:02
| Show all posts
This statement should not be difficult to debug.
  It's possible that your insert statement was written incorrectly, and you can write it differently.
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-17 22:54:01
| Show all posts
DataAdapter.ContinueUpdateOnError = False
It's ok
Reply

Use magic Report

3

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-1-22 22:18:01
| Show all posts
Thank you very much friends for helping the younger brother, especially the friends on the third floor. I use
if is IsNumeric ("") then 'is a number
    'Broadcast data
else
   'Error prompt, exit
end if
Instead of try ... catch statements, I have now solved my long-standing problem.
Thank you guys! ^ _ ^
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