i can't save my data into access using vb.net

Dim SQL As String

        DB.Open()
        Dim Ad As New OleDbDataAdapter("Select * From candidate", DB)
        Dim Check_dataset As DataSet
        Check_dataset = New DataSet("check")
        Ad.Fill(Check_dataset, "check")
        If Check_dataset.Tables("Check").Rows.Count <> 0 Then
            MsgBox("Certificate already exist.!!", MsgBoxStyle.Information, "")
            DB.Close()
            Exit Sub
        End If

        SQL = "INSERT INTO candidate(Cert_No, Cert_Exp_Date, Name, IC_Number, Company, State, Phone_no) values(" _
            & "'" & certNoText.Text & "', " _
            & "'" & DateTimePicker1.Text & "', " _
            & "'" & textName.Text & "', " _
            & "'" & icText.Text & "', " _
            & "'" & comText.Text & "', " _
            & "'" & AddText.Text & "', " _
            & "'" & PhoneText.Text & "')"

        Dc = New OleDbCommand(SQL, DB)
        MessageBox.Show("All data have been save.", " ", MessageBoxButtons.OK, MessageBoxIcon.Information)
        DB.Close()

*when i ru this program, MsgBox("Certificate already exist.!!", MsgBoxStyle.Information, "") will appear.. i don'r where is wrong

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

>i can't save my data into access using vb.net

I can not see any code that insert row into a database.

>when i ru this program, MsgBox("Certificate already exist.!!

Clarify in which circumstances you want to show this message.

Your IF statement is returning that message box if you have any records in your dataset table at all. Second your insert command is never even set to execute anything to the database. You really should start by learning how to step thru your code

Private Sub COnnect()

        Dim Nextb As Long
        Dim PrevB As Long
        Nextb = 0
        PrevB = 0
        Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\zonehirarc.mdb"

        Try
            DB = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;data source='" & STrPath & "'")
            Dc = New OleDbCommand("Select * from candidate where Cert_No <> null")
            DB.Open()

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "")
            End
        End Try
        Dc.Connection = DB
        DB.Close()
    End Sub

    Private Sub save()
        Dim SQL As String

        DB.Open()
        Dim Ad As New OleDbDataAdapter("Select * From candidate", DB)
        Dim Check_dataset As DataSet
        Check_dataset = New DataSet("check")
        Ad.Fill(Check_dataset, "check")
        If Check_dataset.Tables("Check").Rows.Count <> 0 Then
            MsgBox("Certificate already exist.!!", MsgBoxStyle.Information, "")
            DB.Close()
            Exit Sub
        End If

        SQL = "INSERT INTO candidate(Cert_No, Cert_Exp_Date, Name, IC_Number, Company, State, Phone_no) values(" _
            & "'" & certNoText.Text & "', " _
            & "'" & DateTimePicker1.Text & "', " _
            & "'" & textName.Text & "', " _
            & "'" & icText.Text & "', " _
            & "'" & comText.Text & "', " _
            & "'" & AddText.Text & "', " _
            & "'" & PhoneText.Text & "')"

        Dc = New OleDbCommand(SQL, DB)
        MessageBox.Show("All data have been save.", " ", MessageBoxButtons.OK, MessageBoxIcon.Information)
        DB.Close()
        COnnect()

    End Sub

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

Use parametrized query to check whether a certi_no is present in candidate table.

..
  Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\zonehirarc.mdb"
  
  Dim DB as OleDbConnection
  Dim Cmd as New OleDBCommand
  
  DB = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;data source='" & STrPath & "'")

  cmd.CommandText="Select  Cert_no From candidate where Cert_no=@certno"
  cmd.Connection=DB
  cmd.Parameters.AddWithValue("@certno",certNoText.Text)
  
 Dim obj as Object 
 DB.Open()
 obj=cmd.ExecuteScalar()
 DB.Close()

 If IsNothing(obj)=false Then
       MsgBox("Certificate already exist.!!", MsgBoxStyle.Information, "")
       Exit Sub
 End If
..

>addWithValue is not a member of system?

It is not a member of System but it is a member (method) of OleDbCommand class.

This article has been dead for over six months. Start a new discussion instead.