1

i recieve that error but i dont know how to fix, im a student in programming so please help me out, here is my code. Im trying to make a student info for our project

Imports System.Data.OleDb
Imports System.Data

Public Class Form3

    Dim provider As String
    Dim datafile As String
    Dim connstring As String
    Dim connection As OleDbConnection = New OleDbConnection

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ProjectDataSet.Student_Info' table. You can move, or remove it, as needed.
        Me.Student_InfoTableAdapter.Fill(Me.ProjectDataSet.Student_Info)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
        datafile = "D:\Jaja Files\Programming files\Project.mdb"
        connstring = provider & datafile
        connection.ConnectionString = connstring
        connection.Open()
        Dim str As String
        str = "Insert into Student Info([Student ID#],[Given Name],[Surname],[Course],[Year],[Age],[Address],[Contact No],[Email])" + "VALUES (?,?,?,?,?,?,?,?,?)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, connection)
        cmd.Parameters.Add(New OleDbParameter("Student ID#", CType(TextBox1.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Given Name", CType(TextBox3.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Surname", CType(TextBox2.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Course", CType(ComboBox1.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Year", CType(ComboBox2.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Age", CType(TextBox4.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Address", CType(TextBox5.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Contact No", CType(TextBox6.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Email", CType(TextBox7.Text, String)))

        Try
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            connection.Close()
            TextBox1.Clear()
            TextBox2.Clear()
            TextBox3.Clear()
            ComboBox1.ResetText()
            ComboBox2.ResetText()
            TextBox4.Clear()
            TextBox5.Clear()
            TextBox6.Clear()
            TextBox7.Clear()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        StudentInfoBindingSource.EndEdit()
        StudentInfoBindingSource.AddNew()
        Student_InfoTableAdapter.Update(ProjectDataSet.Student_Info)
        MessageBox.Show("Ok Prof!")


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        StudentInfoBindingSource.RemoveCurrent()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Hide()
        Form4.Show()
    End Sub
End Class

i already tried some but still i dont understand how those works,

10
  • Do you know why those brackets are required around some of those column names? It's because of the spaces and other special characters. They aren't required on, for instance, Surname. That applies to any identifiers, including your table name. Commented Aug 20, 2019 at 3:44
  • will try it now, and will update Commented Aug 20, 2019 at 3:45
  • @jmcilhinney i tried but still got the issue Commented Aug 20, 2019 at 3:47
  • "Insert into Student Info([Student ID#],[Given Name], Surname, Course, Year, Age, Address,[Contact No], Email)" + "VALUES (?,?,?,?,?,?,?,?,?)" Commented Aug 20, 2019 at 3:47
  • 1
    Do yourself, and everyone that you'll work with in the future a favor: Don't ever put spaces in the name of a database object, be it a table, a column, or a view. Ever. Just don't. There really is no reason to do so. StudentInfo should suffice as a table name. StudentId should be sufficient as the column name, as GivenName, and SurName. If you really feel the need for a space, use an underscore: Student_Info, Student_ID, Given_Name, etc. Commented Aug 20, 2019 at 11:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.