Add Items From A Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gemmalouise1988
    New Member
    • Oct 2007
    • 10

    Add Items From A Database

    i have created a program that when a user types data , it will search for it, when the user searches for it, i want to make it so the user can add the item and remove the item if they wanted to.

    my coding so far is

    Private Sub cmdSearch_Click ()
    If opt1 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Reference]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    End If

    If opt2 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Item]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    End If

    If opt3 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Item Description]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    End If

    If opt4 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Quantity]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    End If

    If opt5 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Price]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    End If

    txtSearch.Text = ""
    DBGrid1.Visible = True
    End Sub
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by Gemmalouise1988

    [code=vb]
    Private Sub cmdSearch_Click ()

    If opt1.Value = 1Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Reference]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    ElseIf opt2.Value = 1 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Item]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    ElseIf opt3.Value = 1 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Item Description]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    ElseIf opt4.Value = 1 Then
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Quantity]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    Else
    Data1.RecordSou rce = "SELECT * FROM [Table] WHERE [Price]='" & CStr(txtSearch. Text) & "'"
    Data1.Refresh
    End If

    txtSearch.Text = ""
    DBGrid1.Visible = True
    End Sub
    [/code]
    Hi

    Is this working?
    Try the Insert and Delete

    Comment

    • Gemmalouise1988
      New Member
      • Oct 2007
      • 10

      #3
      yes the program does work.

      Comment

      • lotus18
        Contributor
        • Nov 2007
        • 865

        #4
        Originally posted by Gemmalouise1988
        yes the program does work.
        Here's an example for inserting and deleting a record

        [code=vb]

        "Insert Into <TableName> ([<FieldName>]) Values ('" & Text1.Text & "')"

        "Delete From <TableName> Where <FieldName>=' " & Text1.Text & "'"

        [/code]
        Note:

        Omit < and >. For deleting an item, it is recommended to used the primary key in the given sample above

        Comment

        • Gemmalouise1988
          New Member
          • Oct 2007
          • 10

          #5
          so does that add/delete the row onto a new database?

          Comment

          • lotus18
            Contributor
            • Nov 2007
            • 865

            #6
            Originally posted by Gemmalouise1988
            so does that add/delete the row onto a new database?
            Hi Gemmalouise1988

            Nope. This is not for creating a new database but this is for adding/deleting a record from your existing database. Or do I misinterpret your post?

            Comment

            • Gemmalouise1988
              New Member
              • Oct 2007
              • 10

              #7
              sorry i think i didnt explain it properly lol

              i have one database listing all the items

              and then another one so when the user decides to buy an item, it shows what she has bought, and i would like it so if the user decided they didnt want a certain item they could remove it.

              Comment

              • lotus18
                Contributor
                • Nov 2007
                • 865

                #8
                Originally posted by Gemmalouise1988
                sorry i think i didnt explain it properly lol

                i have one database listing all the items

                and then another one so when the user decides to buy an item, it shows what she has bought, and i would like it so if the user decided they didnt want a certain item they could remove it.
                I think you have to create a temporary list of items probably using a listvwiew or listbox, etc to let you view all the items you selected so that you can select the items you want to delete, then when it is final thats the time you save it to your database. btw, pinoy ka?

                Comment

                • Gemmalouise1988
                  New Member
                  • Oct 2007
                  • 10

                  #9
                  ahhh right, i get it

                  THANK YOU!!!

                  Comment

                  Working...