Hi,
i'm working on a system rate analysis.I just worte the code using oop.
i worte a code that inserts a record into the database.when i try to insert a data nothing happens.Please fix my code.

//this code is defined in a class

Public Function AddWorkItem(ByVal workitemNumber As String, ByVal description As String) As Boolean
        Dim val As Boolean
        Dim conn As New OleDbConnection
        Dim cmd As New OleDbCommand
        conn = GetDbConnection()
        Dim s As String = "INSERT INTO work_item ([work item number],[description])VALUES (" &
            "'" & workitemNumber & "','" & description & "')"
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = s
        val = ExecuteCommand(cmd)
        Return val
    End Function

    //this is one used at the clent side
    Dim oWorkItem As WorkItem = New WorkItem()
        Dim result As Boolean
        Dim workitemNumber As String
        Dim description As String

        workitemNumber = TextBox1.Text.ToString
        description = TextBox2.Text.ToString

        result = oWorkItem.AddWorkItem(workitemNumber, description)

        If result = True Then
            MessageBox.Show("Data Added Successfully")
            TextBox1.Text = ""
            TextBox2.Text = ""
            Exit Sub
        End If

I'm not sure what val = ExecuteCommand(cmd) is. If it is meant to be cmd.ExecuteNonQuery() then val returns the number rows affected. If that is not one, the the insert did not happen.

Actually I found my mistake.Execute command is a method which takes a command argument executes and returns a boolean value.Thanks anyway

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.