Click here to Skip to main content
15,892,072 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Entity Framework : Save new object and new childs Pin
desanti28-Oct-16 11:47
desanti28-Oct-16 11:47 
GeneralRe: Entity Framework : Save new object and new childs Pin
Dave Kreskowiak28-Oct-16 12:14
mveDave Kreskowiak28-Oct-16 12:14 
QuestionHow to Get a Folder(shell32) icon into a listview in visual basic 6 - Cannot get this right Pin
4SAI26-Oct-16 6:46
4SAI26-Oct-16 6:46 
QuestionUnderstanding Interface From Previous Developer Pin
hilli_micha26-Oct-16 6:44
hilli_micha26-Oct-16 6:44 
AnswerRe: Understanding Interface From Previous Developer Pin
Richard Deeming26-Oct-16 9:22
mveRichard Deeming26-Oct-16 9:22 
AnswerRe: Understanding Interface From Previous Developer Pin
Ralf Meier30-Oct-16 4:47
mveRalf Meier30-Oct-16 4:47 
GeneralRe: Understanding Interface From Previous Developer Pin
hilli_micha31-Oct-16 1:54
hilli_micha31-Oct-16 1:54 
QuestionCheck if record exists Pin
Member 1281653926-Oct-16 2:55
Member 1281653926-Oct-16 2:55 
Hi,

I am using Visual Studio 2010 and programming in vb. I have a txtbox name "txtFirstName" and a button called "btnCommit". Once the user has added a name to FirstName and clicked the button I need the programme to check the access database tabel to see if the name exists or not. How do I go about doing this?

Thank you in advance for your assistance.





VB.NET
Imports System.Data.OleDb
Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim inc As Integer
    Dim MaxRows As Integer
    Dim dbProvider As String
    Dim dbSource As String
    Dim MyDocumentsFolder As String
    Dim TheDatabase As String
    Dim FullDatabasePath As String
 
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
 
        TheDatabase = "/AddressBook.mdb"
        MyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        FullDatabasePath = MyDocumentsFolder & TheDatabase
 
        dbSource = "Data Source = " & FullDatabasePath
 
        con.ConnectionString = dbProvider & dbSource
 
        con.Open()
 
        sql = "SELECT *FROM tblContacts"
 
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "AddressBook")
 
        con.Close()
 
        MaxRows = ds.Tables("AddressBook").Rows.Count
        inc = -1
    End Sub
    Private Sub NavigateRecords()
 
        txtFirstName.Text = ds.Tables("AddressBook").Rows(inc).Item(1)
        txtSurname.Text = ds.Tables("AddressBook").Rows(inc).Item(2)
        cboxHouse.Checked = ds.Tables("AddressBook").Rows(inc).Item(3)
 
    End Sub
    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If inc <> MaxRows - 1 Then
 
            inc = inc + 1
 
            NavigateRecords()
 
        Else
 
            MessageBox.Show("No More Rows")
 
        End If
    End Sub
    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If inc > 0 Then
 
            inc = inc - 1
 
            NavigateRecords()
 
        ElseIf inc = -1 Then
 
            MessageBox.Show("No Records Yet")
 
        ElseIf inc = 0 Then
 
            MessageBox.Show("First Record")
 
        End If
    End Sub
 
    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        If inc <> MaxRows - 1 Then
 
            inc = MaxRows - 1
 
            NavigateRecords()
 
        End If
    End Sub
 
    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        If inc <> 0 Then
 
            inc = 0
 
            NavigateRecords()
 
        End If
    End Sub
 
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
 
        ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text
        ds.Tables("AddressBook").Rows(inc).Item(2) = txtSurname.Text
        ds.Tables("AddressBook").Rows(inc).Item(3) = cboxHouse.CheckState
        da.Update(ds, "AddressBook")
 
        MessageBox.Show("Data updated")
    End Sub
 
    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
        btnCommit.Enabled = True
        btnAddNew.Enabled = False
        btnUpdate.Enabled = False
        btnDelete.Enabled = False
 
        txtFirstName.Clear()
        txtSurname.Clear()
        txtFirstName.Focus()
 
    End Sub
 
    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        btnCommit.Enabled = False
        btnAddNew.Enabled = True
        btnUpdate.Enabled = True
        btnDelete.Enabled = True
 
        inc = 0
        NavigateRecords()
    End Sub
 
    Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommit.Click
 

 

 
        If inc <> -1 Then
 

            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow
 
            dsNewRow = ds.Tables("AddressBook").NewRow()
 
            dsNewRow.Item("FirstName") = txtFirstName.Text
            dsNewRow.Item("Surname") = txtSurname.Text
            dsNewRow.Item("House") = cboxHouse.CheckState
            ds.Tables("AddressBook").Rows.Add(dsNewRow)
            MaxRows = MaxRows + 1
 

            MessageBox.Show("New Record added to the Database")
 
            btnCommit.Enabled = False
            btnAddNew.Enabled = True
            btnUpdate.Enabled = True >
            btnDelete.Enabled = True
 
            btnCommit.Enabled = False
            btnAddNew.Enabled = True
            btnUpdate.Enabled = True
            btnDelete.Enabled = True
 
            inc = 0
            da.Update(ds, "AddressBook")
            NavigateRecords()
        End If
    End Sub
 
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
 
            MessageBox.Show("Operation Cancelled")
            Exit Sub
 
        End If
        Dim cb As New OleDb.OleDbCommandBuilder(da)
 
        ds.Tables("AddressBook").Rows(inc).Delete()
        MaxRows = MaxRows - 1
 
        inc = 0
        da.Update(ds, "AddressBook")
        NavigateRecords()
    End Sub
 
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Application.Exit()
    End Sub
End Class

AnswerRe: Check if record exists Pin
Richard MacCutchan26-Oct-16 3:20
mveRichard MacCutchan26-Oct-16 3:20 
GeneralRe: Check if record exists Pin
Member 1281653926-Oct-16 3:22
Member 1281653926-Oct-16 3:22 
GeneralRe: Check if record exists Pin
Richard MacCutchan26-Oct-16 3:29
mveRichard MacCutchan26-Oct-16 3:29 
QuestionTreview prevent drag/drop according to destination node Pin
desanti24-Oct-16 9:38
desanti24-Oct-16 9:38 
AnswerRe: Treview prevent drag/drop according to destination node Pin
Michael_Davies24-Oct-16 10:02
Michael_Davies24-Oct-16 10:02 
Questionimage prosseing Pin
Member 1281214124-Oct-16 4:43
Member 1281214124-Oct-16 4:43 
AnswerRe: image prosseing Pin
Dave Kreskowiak24-Oct-16 5:34
mveDave Kreskowiak24-Oct-16 5:34 
QuestionI have no programming knowledge but Pin
Member 1280995223-Oct-16 0:15
Member 1280995223-Oct-16 0:15 
AnswerRe: I have no programming knowledge but Pin
Richard MacCutchan23-Oct-16 5:34
mveRichard MacCutchan23-Oct-16 5:34 
GeneralRe: I have no programming knowledge but Pin
Member 1280995223-Oct-16 9:30
Member 1280995223-Oct-16 9:30 
QuestionUsing a usb barcode reader Pin
desanti20-Oct-16 8:13
desanti20-Oct-16 8:13 
AnswerRe: Using a usb barcode reader Pin
Richard MacCutchan20-Oct-16 20:51
mveRichard MacCutchan20-Oct-16 20:51 
GeneralRe: Using a usb barcode reader Pin
desanti20-Oct-16 22:44
desanti20-Oct-16 22:44 
GeneralRe: Using a usb barcode reader Pin
Eddy Vluggen21-Oct-16 0:01
professionalEddy Vluggen21-Oct-16 0:01 
GeneralRe: Using a usb barcode reader Pin
Richard MacCutchan21-Oct-16 0:28
mveRichard MacCutchan21-Oct-16 0:28 
GeneralRe: Using a usb barcode reader Pin
desanti21-Oct-16 1:16
desanti21-Oct-16 1:16 
GeneralRe: Using a usb barcode reader Pin
Richard MacCutchan21-Oct-16 2:57
mveRichard MacCutchan21-Oct-16 2:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.