Dear all,

I have created project database in msaccessdatabase. It contail Msaccess.jpg

form layout as shown in image & i have attached code for reference

Imports System


Public Class Form1



    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Project_DatabaseDataSet.Project_Data' table. You can move, or remove it, as needed.
        Me.Project_DataTableAdapter.Fill(Me.Project_DatabaseDataSet.Project_Data)
        Dim dt As New Project_DatabaseDataSet.Project_DataDataTable
        For Each col As DataColumn In dt.Columns
            col.AllowDBNull = True
        Next
        Me.Project_DataTableAdapter.FillByMountingType(dt)
        cbo_MountingType.DisplayMember = "Mounting Type"
        cbo_MountingType.DataSource = dt

    End Sub

    Public Sub BindCombox()
        BindComboBox1.DataSource = Project_DatabaseDataSet.Tables("Mounting Type")
        BindComboBox1.DisplayMember = "product Name"

    End Sub


    Public Sub BindComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles BindComboBox1.SelectedIndexChanged


    End Sub


    Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
    End Sub

    Private Sub Project_DataBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Project_DataBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Project_DataBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Project_DatabaseDataSet)

    End Sub



    Private Sub Bt_ADD_Click(sender As Object, e As EventArgs) Handles Bt_ADD.Click
        Project_DataBindingSource.AddNew()
    End Sub




    Private Sub BT_Remove_Click(sender As Object, e As EventArgs) Handles BT_Remove.Click
        Project_DataBindingSource.RemoveCurrent()

    End Sub



    Private Sub Bt_Load_Project_Click(sender As Object, e As EventArgs) Handles Bt_Load_Project.Click

    End Sub



    Private Sub Bt_Search_Click(sender As Object, e As EventArgs) Handles Bt_Search.Click
        Me.Project_DataTableAdapter.FillByAllProject_dataFromMountingType(Me.Project_DatabaseDataSet.Project_Data, cbo_MountingType.Text)
    End Sub

    Private Sub Bt_Project_Save_Click(sender As Object, e As EventArgs) Handles Bt_Project_Save.Click

        Try
            Me.Project_DataBindingSource.EndEdit()
            Project_DataTableAdapter.Update(Project_DatabaseDataSet.Project_Data)
            MessageBox.Show("Data being saved ")
        Catch ex As Exception
            MessageBox.Show("Error while saving data")
        End Try

    End Sub




End Class

Problem i am facing.
1) whenever new data being entered data being populated in datagrid view. If i open ms access database file i found data not being saved

2)I have attached database file for reference . Mounting type & pvsys type are listed value. How to assign combobox value into ms access data base columns .

3)whenever add key is pressed first value store will be empty how to make it to store value with current value

4) Whenever new key pressed how to clear all field & make user to add New values.

Save button codes:

 Private Sub save_Click(sender As Object, e As EventArgs) Handles save.Click
        cmd.Connection = conn
        cmd.CommandText = "INSERT INTO [databasename].[dbo].[tableName] VALUES ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" & TextBox6.Text & "', '" & TextBox7.Text & "', '" & TextBox8.Text & "', '" & TextBox9.Text & "', '" & TextBox10.Text & "')"

        Try
            If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or DateTimePicker2.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or DateTimePicker3.Text = "" Or DateTimePicker4.Text = "" Or y.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Or TextBox10.Text = "" Then
                MessageBox.Show("All fields Are Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                conn.Open() 
                cmd.ExecuteNonQuery()
                MsgBox("Record Successfully Added")
            End If
        Finally
            conn.Close()
        End Try

        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
        TextBox7.Clear()
        TextBox8.Clear()
        TextBox9.Clear()
        TextBox10.Clear()

    End Sub

textboxName.clear() will clear your data typed on textbox

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.