Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim con As New OleDbConnection
        Dim cmd1 As New OleDbCommand
        Dim ddt As New OleDbDataAdapter
        Dim dtd As New DataSet

        con.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Ticket.mdb")
        cmd1.Connection = con
        con.Open()
        cmd1.CommandText = "INSERT INTO regis VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "' ,'" & TextBox3.Text & "' )"
        cmd1.ExecuteNonQuery()
        MessageBox.Show("Succesfully Registered")
        con.Close()


What I have tried:

Please help...i tried checking but its seems good cant know whats the problem
Posted
Updated 20-Oct-16 7:24am
v2
Comments
[no name] 20-Oct-16 13:07pm    
Other than the obvious SQL injection attack invitation, the error message tells you exactly what the problem is. The number of values you are trying to stuff into regis do not match.

1 solution

Never rely on the implicit column amount or order in an INSERT statement. Instead, define all the columns you're going to use. So the syntax should be
SQL
INSERT INTO TableName
(ColumnName, ColumnName, ...)
VALUES
(Value, Value, ...)

And the other thing is that you should always use parameters with queries. Never concatenate values directly to SQL statements. For more information have a look at OleDbParameter Class (System.Data.OleDb)[^]

Also you should use using statement to ensure that objects are properly disposed. Even though the article is written about SqlCommands, have a look at Properly executing database operations[^] The same principles apply to OleDbCommand.
 
Share this answer
 
v2
Comments
Maciej Los 20-Oct-16 13:49pm    
5ed!
Wendelius 20-Oct-16 14:52pm    
Thanks :)
Member 12805540 21-Oct-16 7:18am    
I'm using access data base ...so please help me ...not able to execute
Wendelius 21-Oct-16 10:56am    
You didn't explain the problem. If the problem is still the same, modify the INSERT statement to include all the columns you need to fill and also provide values for all these columns.

If you need further help, post the current SQL statement you have, the error you get and definition for the table.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900