locked
School project in VB.NET. RRS feed

  • Question

  • Hi all,

     

    I'm desparade really desparade to complete my school project. I need help real bad.

    My programe knowledge is zero. I pick up VB.NET after viewing the video lesson download form msdn.com.

    I find it very interesting and easy to pick up. But as I start developing it's more complicated than I tot it is.

    Now I'm stuck and I need to submit this project this Friday.

     

    It's really driving me nuts, is there anyone out there who is willing to help me. I just need to get this application up by being able to update, edit & delete. I can't ask for more. This will help me at least a pass in my project module.

     

    Please, please someone out there please help me....

     

    Kamal

    Monday, November 26, 2007 10:58 AM

Answers

  •  

     kamal kim wrote:

    What trouble are you having with these items?

    "But up todate I'm still unable to make the forms to update, edit & delete any records properly"

    in the application that I'm developing, I'm suppose to keep a records of devices. Who are the user? Where is it located? What's the monthly subscription for the devices?

     

    I have 5 different forms, to keep records of User, Equipment, Staff, RequestForm and lastly Transaction Form. As mentioned earlier, I'm using BindingNavigator to update records in the Db. But's its not working as shown in the video tutorial. I'm using SQL as my Db.

     

     

    To use BindingNavigator control to make a data access project, here are these steps I made:

     

    Presume an existing SQL Server database StaffDB.mdf which has a table Staff.

    The table has five fields (Text type):

    StaffNumber (set as Primary key)

    StaffName

    Designation

    Department

    Location

     

    1.  Data menu -> Add New Data Source

    During wizard, select StaffDB.mdf and Staff table, finishing it will create a StaffDBDataSet.xsd file in Solution Explorer.

     

    2.  Data menu -> Show Data Sources  

    In Data Sources panel, drag&drop each data field to Form in turn in order to bind individual data.

    During this process, the StaffDBDataSet, StaffTableAdapter, StaffBindingNavigator and StaffBindingSource controls will be added automatically to Form, and five pairs of Label and TextBox controls will be added to Form.

     

     

    3.    Set StaffBindingNavigator.BindingSource property as StaffBindingSource in Properties panel.

     

    4.    Set StaffBindingSource.DataSource property as StaffDBDataSet in Properties panel.

     

    5.    Add code in Form1.vb to Save event handle.

    Code Block

        Private Sub StaffBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click

            Me.Validate()

            Me.StaffBindingSource.EndEdit()

            Me.StaffTableAdapter.Update(Me.StaffDBDataSet.Staff)

            Me.StaffDBDataSet.AcceptChanges()

    End Sub

     

     

    6.  Right-click the database file StaffDB.mdf in Solution Explorer -> change the "copy to output directory" property to "copy if newer".

     

    Then you can insert/delete/update/save records without any error.

     

    • Edited by Xingwei Hu Monday, February 23, 2009 9:35 AM ........
    Wednesday, November 28, 2007 8:20 AM

All replies

  • Beth Massi Forms over Data Video Series will help.  You will find the data half way down the webpage

     

    http://msdn2.microsoft.com/en-us/vbasic/bb466226.aspx?wt.slv=topsectionsee

     

    Monday, November 26, 2007 11:09 AM
  • Well Kamal I will help you out since I am also in school Big Smile

    What sort of help do you need ?!
    Monday, November 26, 2007 11:58 AM
  • What problems are you having?

     

    Adam

    Monday, November 26, 2007 12:07 PM
  • Morning guys, as mentioned earlier, I'm putting up an inventory system which able to do device tracking and budgeting. But up todate I'm still unable to make the forms to update, edit & delete any records properly. I'm using the Binding Navigator as taught in the video download. It look so simple, but I don't understand why I can't get it right.

     

    My main intention now is just to make it able to update, edit & delete records. And lastly I need to know how to deploy this to another work area. The due date is this Friday. And I'm stucked. Please help...

    Tuesday, November 27, 2007 1:45 AM
  • You need to build the UPDATE AND DELETE commands.

     

    Update = Update MyTable SET FName = @Fname WHERE employeeid = @EmployeeID

    DELETE = DELETE FROM MyTable WHERE employeeid = @EmployeeID

     

    Adam

    Tuesday, November 27, 2007 2:20 AM
  • If Adam's suggestion didn't fix your problem then you need to be more specific.

     

    What trouble are you having with these items?

    "But up todate I'm still unable to make the forms to update, edit & delete any records properly"

     

    And what does this mean?

    "And lastly I need to know how to deploy this to another work area"

     

    Deploy what?

    And to where?

    Tuesday, November 27, 2007 3:22 AM
  • Hi,

     

    What trouble are you having with these items?

    "But up todate I'm still unable to make the forms to update, edit & delete any records properly"

    in the application that I'm developing, I'm suppose to keep a records of devices. Who are the user? Where is it located? What's the monthly subscription for the devices?

     

    I have 5 different forms, to keep records of User, Equipment, Staff, RequestForm and lastly Transaction Form. As mentioned earlier, I'm using BindingNavigator to update records in the Db. But's its not working as shown in the video tutorial. I'm using SQL as my Db.

     

    And what does this mean?

    "And lastly I need to know how to deploy this to another work area"

    During the submission of the project, I'm suppose to do a presentation to the lecturer on how the application works and how to deploy it to the enduser pc. That's what I meant by deploying to another work area.

     

    Tuesday, November 27, 2007 4:01 AM
  • Have you built the tables in SQL Server yet?

     

    Adam

    Tuesday, November 27, 2007 11:59 AM
  • Yes I've done that.

     

    Please send me ur email add and I will send it to you...
    Wednesday, November 28, 2007 3:06 AM
  •  

     kamal kim wrote:

    What trouble are you having with these items?

    "But up todate I'm still unable to make the forms to update, edit & delete any records properly"

    in the application that I'm developing, I'm suppose to keep a records of devices. Who are the user? Where is it located? What's the monthly subscription for the devices?

     

    I have 5 different forms, to keep records of User, Equipment, Staff, RequestForm and lastly Transaction Form. As mentioned earlier, I'm using BindingNavigator to update records in the Db. But's its not working as shown in the video tutorial. I'm using SQL as my Db.

     

     

    To use BindingNavigator control to make a data access project, here are these steps I made:

     

    Presume an existing SQL Server database StaffDB.mdf which has a table Staff.

    The table has five fields (Text type):

    StaffNumber (set as Primary key)

    StaffName

    Designation

    Department

    Location

     

    1.  Data menu -> Add New Data Source

    During wizard, select StaffDB.mdf and Staff table, finishing it will create a StaffDBDataSet.xsd file in Solution Explorer.

     

    2.  Data menu -> Show Data Sources  

    In Data Sources panel, drag&drop each data field to Form in turn in order to bind individual data.

    During this process, the StaffDBDataSet, StaffTableAdapter, StaffBindingNavigator and StaffBindingSource controls will be added automatically to Form, and five pairs of Label and TextBox controls will be added to Form.

     

     

    3.    Set StaffBindingNavigator.BindingSource property as StaffBindingSource in Properties panel.

     

    4.    Set StaffBindingSource.DataSource property as StaffDBDataSet in Properties panel.

     

    5.    Add code in Form1.vb to Save event handle.

    Code Block

        Private Sub StaffBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click

            Me.Validate()

            Me.StaffBindingSource.EndEdit()

            Me.StaffTableAdapter.Update(Me.StaffDBDataSet.Staff)

            Me.StaffDBDataSet.AcceptChanges()

    End Sub

     

     

    6.  Right-click the database file StaffDB.mdf in Solution Explorer -> change the "copy to output directory" property to "copy if newer".

     

    Then you can insert/delete/update/save records without any error.

     

    • Edited by Xingwei Hu Monday, February 23, 2009 9:35 AM ........
    Wednesday, November 28, 2007 8:20 AM
  • In addition using BindingNavigator control, you also can implement data access (Next, Previous, First, Last, Update, Delete, Insert, Save) in code.

     

    Take the Equipment table for example:

    Code Block

    Imports System.Data.SqlClient

     

    Public Class Equipment

        Dim cmd As SqlCommand

        Dim myAdapter As New SqlDataAdapter

        Dim comBuilder As SqlCommandBuilder

        Dim ds As DataSet

        Dim mytable As DataTable

        Dim myrow As Data.DataRow

        Dim rownumber As Integer

     

        Private Sub Equipment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\TeleInventory.mdf;Integrated Security=True;User Instance=True")

            myAdapter.SelectCommand = New SqlCommand("SELECT * FROM Equipment", con)

            comBuilder = New SqlCommandBuilder(myAdapter)

            con.Open()

            rownumber = 0

            ShowData()

        End Sub

     

        Private Sub ShowData()

            ds = New DataSet()

            myAdapter.Fill(ds, "EquipmentTable")

            mytable = ds.Tables("EquipmentTable")

            myrow = mytable.Rows.Item(rownumber)

            TextBox1.Text = myrow.Item("EquptID").ToString

            TextBox2.Text = myrow.Item("EqptType").ToString

            TextBox3.Text = myrow.Item("EqptNumber").ToString

            TextBox4.Text = myrow.Item("Status").ToString

            TextBox5.Text = myrow.Item("CostCenter").ToString

            TextBox6.Text = myrow.Item("WalkieSN").ToString

        End Sub

     

        ' First record

        Private Sub FirstButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FirstButton.Click

            rownumber = 0

            ShowData()

            PreviousButton.Enabled = False

            NextButton.Enabled = True

        End Sub

     

        'Next record

        Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click

            PreviousButton.Enabled = True

            rownumber = rownumber + 1

            If rownumber > mytable.Rows.Count - 1 Then

                rownumber = mytable.Rows.Count - 1

                NextButton.Enabled = False

            End If

            ShowData()

        End Sub

     

        'Previous record

        Private Sub PreviousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousButton.Click

            NextButton.Enabled = True

            rownumber = rownumber - 1

            If rownumber < 0 Then

                rownumber = 0

                PreviousButton.Enabled = False

            End If

            ShowData()

        End Sub

     

        'Last record

        Private Sub LastButto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LastButton.Click

            rownumber = mytable.Rows.Count - 1

            ShowData()

            NextButton.Enabled = False

            PreviousButton.Enabled = True

        End Sub

     

      ' To be continued...

    End Class

    Wednesday, November 28, 2007 8:33 AM
  • Continue...

    Code Block

     

    ' Update/Edit

        Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click

            If TextBox1.Text.Trim = "" Then

                MessageBox.Show(" Please input EquipID?")

                TextBox1.Focus()

            End If

     

            myrow.Item("EquptID") = TextBox1.Text.Trim

            myrow.Item("EqptType") = TextBox2.Text.Trim

            myrow.Item("EqptNumber") = TextBox3.Text.Trim

            myrow.Item("Status") = TextBox4.Text.Trim

            myrow.Item("CostCenter") = TextBox5.Text.Trim

            myrow.Item("WalkieSN") = TextBox6.Text.Trim

     

            mytable.GetChanges()

            comBuilder.GetUpdateCommand()

            myAdapter.Update(ds, "EquipmentTable")

        End Sub

     

        'Delete record

        Private Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteButton.Click

            mytable.Rows.Item(rownumber).Delete()

            If MessageBox.Show("DO you really delete it ?") = MsgBoxResult.Ok Then

                comBuilder.GetUpdateCommand()

                myAdapter.Update(ds, "EquipmentTable")

                NextButton.PerformClick()

            End If

        End Sub

     

        'Click Insert button to empty each TextBox

        Private Sub InsertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertButton.Click

            mytable.Rows.Add()

            rownumber = mytable.Rows.Count - 1

            myrow = mytable.Rows.Item(rownumber)

            TextBox1.Text = ""

            TextBox2.Text = ""

            TextBox3.Text = ""

            TextBox4.Text = ""

            TextBox5.Text = ""

            TextBox6.Text = ""

        End Sub

     

        ' After clicking Insert button, then clicking Save button

        Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click

            If TextBox1.Text.Trim = "" Then

                MessageBox.Show("Please input EquipID?")

                TextBox1.Focus()

            End If

     

            myrow.Item("EquptID") = TextBox1.Text.Trim

            myrow.Item("EqptType") = TextBox2.Text.Trim

            myrow.Item("EqptNumber") = TextBox3.Text.Trim

            myrow.Item("Status") = TextBox4.Text.Trim

            myrow.Item("CostCenter") = TextBox5.Text.Trim

            myrow.Item("WalkieSN") = TextBox6.Text.Trim

     

            mytable.GetChanges()

            comBuilder.GetInsertCommand()

            myAdapter.Update(ds, "EquipmentTable")

        End Sub

     

     

    Wednesday, November 28, 2007 8:35 AM
  •  kamal kim wrote:

    And what does this mean?

    "And lastly I need to know how to deploy this to another work area"

    During the submission of the project, I'm suppose to do a presentation to the lecturer on how the application works and how to deploy it to the enduser pc. That's what I meant by deploying to another work area.

     

    Step 1: Add a Lecturer form containing a PictureBox and a RichTextBox.

    Public Class Lecturer

     

        Private Sub Lecturer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            PictureBox1.Image = Image.FromFile("E:\TeleInventory\Lecturer.gif")

            RichTextBox1.Text = "How the application works and How to deploy it to the end-user pc"

        End Sub

    End Class

    Step 2: Add a Button to MainMenu form and handle Button_Click event.

    Public Class MainMenu

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim Myform As New Lecturer

            Myform.Show()

        End Sub

    End Class

    Wednesday, November 28, 2007 8:41 AM
  •  

    I have try to use these code to write a program.
    But the error "There is no row at position 0." will be present when there is no data in my table.

     

    How can I solve this problem in fact i can use the "insert" function to enter the first record ?

    Monday, February 25, 2008 9:11 AM
  • This error message is probably due to an issue with the dataset your using. Make sure not to create an untyped dataset

    with the same name as the one in your code and also make sure you declare it Public >> Dim ds As DataSet. Thanks Charlie

     

    Tuesday, September 9, 2008 3:40 AM
  • Hi there, Thanks for your submission helped me heaps!!

     

    However.... When using the INSERT/DELETE/UPDATE statements it works only temporarly

    e.g. after inserting (and saving) a new record, I can move to the previous record, then forward (bringing me back to the record I just inserted) and that is fine, . . however when I close the application and check the database,  I see the changes I made to the table have not occured. . however they seem to work fine at runtime. . . any idea??

     

     

    I hope this was explained well enough.  Basically the changes I make are only effictive at runtime and do not effect the database.  Please help..

     

     

    I have altered the above code slightly here it is below; 

     

    My Database name is: Database.MDF

     

    I have one table (tblNames) with three columns (RowIndex, FirstName, LastName)  Hopefully someone can help me solve my problem.

     

    Code Snippet

     

    Imports System.Data.SqlClient

     

    Public Class Form1

    #Region "Declarations"

    Dim SqlCmd As SqlCommand

    Dim NamesAdapter As New SqlDataAdapter

    Dim SqlComBuild As SqlCommandBuilder

    Dim NamesDataSet As DataSet

    Dim NamesTable As DataTable

    Dim NamesRow As Data.DataRow

    Dim NamesRowNo As Integer

    Dim SqlConn As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.Mdf;Integrated Security=True;User Instance=True")

    #End Region

     

     

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    NamesAdapter.SelectCommand = New SqlCommand("SELECT * FROM tblNames", SqlConn)

    SqlComBuild = New SqlCommandBuilder(NamesAdapter)

    SqlConn.Open()

    NamesRowNo = 0

    DisplayNamesData()

     

    End Sub

     

    Private Sub DisplayNamesData()

    NamesDataSet = New DataSet()

    NamesAdapter.Fill(NamesDataSet, "tblNames")

    NamesTable = NamesDataSet.Tables("tblNames")

    Try

    NamesRow = NamesTable.Rows.Item(NamesRowNo)

    txtRowIndex.Text = NamesRow.Item("RowIndex").ToString

    txtFirstName.Text = NamesRow.Item("FirstName").ToString

    txtLastName.Text = NamesRow.Item("LastName").ToString

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

     

    End Sub

     

    Private Sub FirstButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FirstButton.Click

    NamesRowNo = 0

    DisplayNamesData()

    PreviousButton.Enabled = False

    NextButton.Enabled = True

    End Sub

     

    Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click

    PreviousButton.Enabled = True

    NamesRowNo = NamesRowNo + 1

    If NamesRowNo > NamesTable.Rows.Count - 1 Then

    NamesRowNo = NamesTable.Rows.Count - 1

    NextButton.Enabled = False

    End If

    DisplayNamesData()

    End Sub

     

    Private Sub PreviousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousButton.Click

    NextButton.Enabled = True

    NamesRowNo = NamesRowNo - 1

    If NamesRowNo < 0 Then

    NamesRowNo = 0

    PreviousButton.Enabled = False

    End If

    DisplayNamesData()

    End Sub

     

    Private Sub LastButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LastButton.Click

    NamesRowNo = NamesTable.Rows.Count - 1

    DisplayNamesData()

    NextButton.Enabled = False

    PreviousButton.Enabled = True

    End Sub

    Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click

    If txtFirstName.Text.Trim = "" And txtLastName.Text.Trim = "" Then

    MessageBox.Show("All Feilds Required")

    txtFirstName.Focus()

    Exit Sub

    End If

     

    NamesRow.Item("FirstName") = txtFirstName.Text.Trim

    NamesRow.Item("LastName") = txtLastName.Text.Trim

    NamesTable.GetChanges()

    SqlComBuild.GetUpdateCommand()

    NamesAdapter.Update(NamesDataSet, "tblNames")

     

    End Sub

     

     

    Private Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteButton.Click

    NamesTable.Rows.Item(NamesRowNo).Delete()

    If MessageBox.Show("Delete this record?") = MsgBoxResult.Ok Then

    SqlComBuild.GetUpdateCommand()

    NamesAdapter.Update(NamesDataSet, "tblNames")

    NextButton.PerformClick()

    End If

    End Sub

     

    Private Sub InsertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertButton.Click

    NamesTable.Rows.Add()

    NamesRowNo = NamesTable.Rows.Count - 1

    NamesRow = NamesTable.Rows.Item(NamesRowNo)

    txtRowIndex.Text = ""

    txtFirstName.Text = ""

    txtLastName.Text = ""

    End Sub

     

    Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click

    If txtFirstName.Text.Trim = "" And txtLastName.Text.Trim = "" Then

    MessageBox.Show("All Feilds Required")

    txtFirstName.Focus()

    Exit Sub

    End If

     

    NamesRow.Item("FirstName") = txtFirstName.Text.Trim

    NamesRow.Item("LastName") = txtLastName.Text.Trim

    NamesTable.GetChanges()

    SqlComBuild.GetInsertCommand()

    NamesAdapter.Update(NamesDataSet, "tblNames")

    NamesTable.EndLoadData()

     

     

    End Sub

    End Class

     

     

    Thanks

     

    -Dan

    Wednesday, October 15, 2008 7:10 AM
  • Im not to sure what exactly what your trying to insert in the database but I have wrote the code below for you and this will insert data from textbox and into the database. Please note you can use this same code with comboboxes, memo, richtext, any other text controls. Thanks Charlie

     

    Try

    Dim myconn As New SqlConnection(connectionstring) 'You must store your connection string in the () If not stored use " "

    Dim strSQL As String

    strSQL = "INSERT into Table1(entry1, entry2, entry3, entry4) Values (@entry1, @entry2, @entry3, @entry4)"

    Dim myCMD As New SqlCommand(strSQL, myconn)

    myCMD.Parameters.Add("@entry1", SqlDbType.NVarChar, 23)

    myCMD.Parameters.Add("@entry2", SqlDbType.NVarChar, 23)

    myCMD.Parameters.Add("@entry3", SqlDbType.NVarChar, 23)

    myCMD.Parameters.Add("@entry4", SqlDbType.NVarChar, 23)

    'Parameter Values

    myCMD.Parameters("@entry1").Value = txtentry1.Text

    myCMD.Parameters("@entry2").Value = txtentry2.Text

    myCMD.Parameters("@entry3").Value = txtentry3.Text

    myCMD.Parameters("@entry4").Value = txtentry4.Text

    'Open Connection

    myconn.Open()

    myCMD.ExecuteNonQuery()

    Catch ex As Exception

    MessageBox.Show(ex.ToString)

    End Try

    Wednesday, October 15, 2008 5:11 PM
  • The problem you are having when you insert data and it fine at run time but when you restart the program it's gone. I believe this is due to the setting in your project under the database properties found in the solutions explorer are not set to copy. So find your database in the solution explorer and just highlight the database and go down to the properties. While your looking through them find the one that says "copy output directory" and change that to "copy if newer'. That should fix your issue if you’re working with local database. Thanks Charlie

    Wednesday, October 15, 2008 5:18 PM
  • this thread was alot of help when it came to setting up connections and working with them.  i was also able to fix an issue where i had to make sure my my compiler was buidling my app in x86 mode verses 64 bit vista mode.  Thanks alot guys. 
    Wednesday, February 11, 2009 6:14 AM
  • Hi Martin,

    I´m working on a simple form that has 14 text boxes. I have a database in access 2007 called Info where i´m storing this textboxes. How would i do exactly the same thing posted on this forum to apply it to my form?. This code works for a SQL database, i´m using access.

    Thanks
    Tuesday, June 23, 2009 7:52 PM
  • Josh,

    Do you need to store all of the pieces of data (text boxes) or just one and it's number or is the data somewhere in between?
    -Renee
    Tuesday, June 23, 2009 10:45 PM
  • Hi Renee, this is the problem i´m having

    I´m trying to save the information on the textboxes to a table called info in access i tried coding my application two different times and still get the same error (Syntax error in INSERT INTO statement.) Can someone help me with this? Here´s my application code. I only need the button that saves the records to the database fields working. I keep searching for answers and can´t get it to work. The error points to this line of code. I´ll appreciate any kind of help with this.

    dataAdapter.Update(dataTable)

    on btnCommit

    Imports System
    Imports System.Data
    Imports System.Data.OleDb
    
    Public Class Form1
        Public cnADONetConnection As New OleDb.OleDbConnection() 'STEP 1 - ADO.Net CONNECTION
        Public dataAdapter As OleDb.OleDbDataAdapter 'STEP 5 - DATA ADAPTER
        Public commandBuilder As OleDb.OleDbCommandBuilder 'STEP 6 - COMMAND BUILDER
        Public dataTable As New DataTable 'STEP 7 - DATA SET aka DATA TABLE
    
        Dim m_rowPosition As Integer = 0
    
        Private Sub ShowCurrentRecord()
            If dataTable.Rows.Count = 0 Then
                txtevname.Text = ""
                txtname.Text = ""
                txtcompany.Text = ""
                EvalDate.Text = ""
                txtSup.Text = ""
                txtCase.Text = ""
                txtservice.Text = ""
                txtPriority.Text = ""
                txtstatus.Text = ""
                ResDate.Text = ""
                txtOport.Text = ""
                txtdefect.Text = ""
                txtcomp.Text = ""
                txttotdef.Text = ""
                Exit Sub
            End If
    
            txtevname.Text = dataTable.Rows(m_rowPosition)("Evaluator Name").ToString()
            txtname.Text = dataTable.Rows(m_rowPosition)("Evaluated Engineer").ToString()
            txtcompany.Text = dataTable.Rows(m_rowPosition)("Company Supported").ToString()
            EvalDate.Text = dataTable.Rows(m_rowPosition)("Evaluation date").ToString()
            txtSup.Text = dataTable.Rows(m_rowPosition)("Supervisor").ToString()
            txtCase.Text = dataTable.Rows(m_rowPosition)("Case ID").ToString()
            txtservice.Text = dataTable.Rows(m_rowPosition)("Service Type").ToString()
            txtPriority.Text = dataTable.Rows(m_rowPosition)("Priority").ToString()
            txtstatus.Text = dataTable.Rows(m_rowPosition)("Status").ToString()
            ResDate.Text = dataTable.Rows(m_rowPosition)("Resolved date").ToString()
            txtOport.Text = dataTable.Rows(m_rowPosition)("Total opportunities").ToString()
            txtdefect.Text = dataTable.Rows(m_rowPosition)("Total defects").ToString()
            txtcomp.Text = dataTable.Rows(m_rowPosition)("Compliance").ToString()
            txttotdef.Text = dataTable.Rows(m_rowPosition)("Defect percentage").ToString()
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            cnADONetConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\lojesusm\Desktop\Useful Info\Visual Basic\Evaluation.mdb;Persist Security Info=False;" 'STEP 2
            cnADONetConnection.Open() 'STEP 3
    
            dataAdapter = New OleDb.OleDbDataAdapter("Select * From Info", cnADONetConnection) 'STEP 5
            commandBuilder = New OleDb.OleDbCommandBuilder(dataAdapter) 'STEP 6
            dataAdapter.Fill(dataTable) 'STEP 8
    
            ShowCurrentRecord()
        End Sub
    
        Private Sub evaluate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles evaluate.Click
            Dim county As Integer
            Dim countn As Integer
            Dim countna As Integer
            Dim countall As Integer
            Dim deftotcount As Double
            Dim compcount As Double
    
            If rdyes1.Checked = True Then
                county = county + 1
            ElseIf rdno1.Checked = True Then
                countn = countn + 1
            ElseIf rdna1.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes2.Checked = True Then
                county = county + 1
            ElseIf rdno2.Checked = True Then
                countn = countn + 1
            ElseIf rdna2.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes3.Checked = True Then
                county = county + 1
            ElseIf rdno3.Checked = True Then
                countn = countn + 1
            ElseIf rdna3.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes4.Checked = True Then
                county = county + 1
            ElseIf rdno4.Checked = True Then
                countn = countn + 1
            ElseIf rdna4.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes5.Checked = True Then
                county = county + 1
            ElseIf rdno5.Checked = True Then
                countn = countn + 1
            ElseIf rdna5.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes6.Checked = True Then
                county = county + 1
            ElseIf rdno6.Checked = True Then
                countn = countn + 1
            ElseIf rdna6.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes7.Checked = True Then
                county = county + 1
            ElseIf rdno7.Checked = True Then
                countn = countn + 1
            ElseIf rdna7.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes8.Checked = True Then
                county = county + 1
            ElseIf rdno8.Checked = True Then
                countn = countn + 1
            ElseIf rdna8.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes9.Checked = True Then
                county = county + 1
            ElseIf rdno9.Checked = True Then
                countn = countn + 1
            ElseIf rdna9.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes10.Checked = True Then
                county = county + 1
            ElseIf rdno10.Checked = True Then
                countn = countn + 1
            ElseIf rdna10.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes11.Checked = True Then
                county = county + 1
            ElseIf rdno11.Checked = True Then
                countn = countn + 1
            ElseIf rdna11.Checked = True Then
                countna = countna + 1
            End If
    
            If rdyes12.Checked = True Then
                county = county + 1
            ElseIf rdno12.Checked = True Then
                countn = countn + 1
            ElseIf rdna12.Checked = True Then
                countna = countna + 1
            End If
    
            txtOport.Text = county
            txtdefect.Text = countn
    
            countall = county + countn
    
            deftotcount = (countn / countall) * 100
            txttotdef.Text = deftotcount
    
            compcount = ((countall - countn) / countall) * 100
            txtcomp.Text = compcount
        End Sub
    
        Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
            If m_rowPosition < (dataTable.Rows.Count - 1) Then
                m_rowPosition = m_rowPosition + 1
                Me.ShowCurrentRecord()
            Else
                MsgBox("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 m_rowPosition > 0 Then
                m_rowPosition = m_rowPosition - 1
                Me.ShowCurrentRecord()
            Else
                MsgBox("First Record")
            End If
        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
    
            txtevname.Clear()
            txtname.Clear()
            txtcompany.Clear()
            txtSup.Clear()
            txtCase.Clear()
            txtservice.Clear()
            txtPriority.Clear()
            txtstatus.Clear()
            txtOport.Clear()
            txtdefect.Clear()
            txtcomp.Clear()
            txttotdef.Clear()
        End Sub
    
        Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommit.Click
    
            Dim drNewRow As DataRow = dataTable.NewRow()
            drNewRow("Evaluator Name") = txtevname.Text
            drNewRow("Evaluated Engineer") = txtname.Text
            drNewRow("Company Supported") = txtcompany.Text
            drNewRow("Evaluation date") = EvalDate.Text
            drNewRow("Supervisor") = txtSup.Text
            drNewRow("Case ID") = txtCase.Text
            drNewRow("Service Type") = txtservice.Text
            drNewRow("Priority") = txtPriority.Text
            drNewRow("Status") = txtstatus.Text
            drNewRow("Resolved date") = ResDate.Text
            drNewRow("Total opportunities") = txtOport.Text
            drNewRow("Total defects") = txtdefect.Text
            drNewRow("Compliance") = txtcomp.Text
            drNewRow("Defect percentage") = txttotdef.Text
       
            dataTable.Rows.Add(drNewRow)
            dataAdapter.Update(dataTable)
            m_rowPosition = dataTable.Rows.Count - 1
            Me.ShowCurrentRecord()
    
        End Sub
    Wednesday, June 24, 2009 8:34 PM
  • The problem you are having when you insert data and it fine at run time but when you restart the program it's gone. I believe this is due to the setting in your project under the database properties found in the solutions explorer are not set to copy. So find your database in the solution explorer and just highlight the database and go down to the properties. While your looking through them find the one that says "copy output directory" and change that to "copy if newer'. That should fix your issue if you’re working with local database. Thanks Charlie


    Hey Charlieit123

    I've already change my database (MPESystem.mdf) setting in the properties to "copy if newer". But is still not working .. it work perfectly fine in run time. However, when i restart the program. It when missing again.

    Thursday, July 22, 2010 3:11 PM
  • Hi Adam,

    Can you explain me how to build the UPDATE AND DELETE commands.

    Thanks


    Shajahan
    Saturday, May 28, 2011 6:26 AM