Hey , am currently doing my school project of coming up with school reports of learners but when I tried to connect my database with the ms vb it gave me an insert into error whil I was trying to register learners .Please help.

Can't offer much help unless we can see what you have done so far. Post your code.

Imports System.Data.OleDb

Public Class Registetration_of_learners
    Dim provider As String
    Dim dataFile As String
    Dim connString As String
    Public myConnection As OleDbConnection = New OleDbConnection
    Public dr As OleDbDataReader

    Dim learnername As String
    Dim learnersurname As String
    Dim dateofbirth As Date
    Dim gender As String
    Dim studentno As Integer
    Dim grade As String

    Private Sub Registration_of_learners_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
        dataFile = "C:\Users\nnashipili\Documents\Visual Studio 2010\Projects\Reports Management System\WindowsApplication3\Podheni_Matete.accdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString
    End Sub

    Private Sub RRegisterButton_Click(sender As Object, e As System.EventArgs) Handles RRegisterButton.Click

        myConnection.Open()
        Dim str As String
        str = "INSERT INTO Learners ([Registration_number], [Learner's_name], [Learner's_surname], [Date_Of_Birth], [Grade],[Gender],) values ([studentno], [learnername], [learnersurname], [dateofbirth], [grade],[Gender])"

        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)

        cmd.Parameters.Add(New OleDbParameter("studentno", CType(RStudentNo_TextBox.Text, Integer)))
        cmd.Parameters.Add(New OleDbParameter("learnername", CType(RNameTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("learnersurname", CType(RSurnameTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("dateofbirth", CType(RDOBTextBox.Text, Date)))
        cmd.Parameters.Add(New OleDbParameter("grade", CType(RGradeTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Gender", CType(RGenderComboBox.SelectedItem, String)))

        Try
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            MessageBox.Show("Successfully Registered!")
            RNameTextBox.Clear()
            RSurnameTextBox.Clear()
            RGradeTextBox.Clear()
            RGenderComboBox.Text = String.Empty
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        myConnection.Close()
    End Sub

    Private Sub RGenderComboBox_Click(sender As Object, e As System.EventArgs) Handles RGenderComboBox.Click
        RGenderComboBox.Items.Clear()
        RGenderComboBox.Items.Add("Male")
        RGenderComboBox.Items.Add("Female")
    End Sub
    Private Sub RBackButton_Click(sender As Object, e As System.EventArgs) Handles RBackButton.Click
        Activity_selection.Show()
        Me.Close()
    End Sub

End Class

Typically, when you do an INSERT you include some values to go with the field names. For example

INSERT INTO mytable (LastName,FirstName,Age) VALUES('Smith','George',27)

Your query didn't do this.

I'll also add that you should be using Parameterized Queries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.