Member Avatar for westsiderailway

hi everyone,
I am a newbee when dealing with databases....

so far i have a sql database in my sql server(local).

Have open a project in vs2010express and have connected it to my DB.

on my form i have the datagridview populated with my database, have buttons that can add ,(move to next,previous) and delete.

the columns in my DB are ID,Date,Time,Place,Price per Liter,Total Liters,Total Price and Pump Number.
so the columns are of type date,time,text,money,integer,money and integer.

on my form2, i have textboxes for all the columns and have a textbox for entering the data to find, and finally have a button to start the search.

Now what i want to do is enter a date and have the textboxes filled with the data for that date.

Thank you to everyone who reads and hopefully helps me with this problem.

Rdgs.

Michael

ps. i have looked at other questions like this,but, they do not make any sense to me, and i do not know how to make them work for me.

Recommended Answers

All 3 Replies

Member Avatar for westsiderailway

hi everyone,

Have figured out this so far....

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

        If TextBox8.Text = "" Then
            MsgBox("ERROR, You Must INPUT a Date to Begin a SEARCH")

        End If

        Dim rowCount As Integer
        Dim i As Integer

        rowCount = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells.Count

        Dim message As String = ""

        For i = 1 To rowCount - 1
            message = message & " " & Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(i).Value.ToString

            'Find the date that the user entered

            If Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(1).Value.ToString = TextBox8.Text Then

                ' if the date the user entered is found
                'send cells of current row to Textboxes

                '  If i = 1 Then
                TextBox1.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(1).Value.ToString
                '  End If
                'If i = 2 Then
                TextBox2.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(2).Value.ToString
                'End If
                'If i = 3 Then
                TextBox3.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(3).Value.ToString
                'End If
                'If i = 4 Then
                TextBox4.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(4).Value.ToString
                'End If
                'If i = 5 Then
                TextBox5.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(5).Value.ToString
                'End If
                'If i = 6 Then
                TextBox6.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(6).Value.ToString
                'End If
                'If i = 7 Then
                TextBox7.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(7).Value.ToString
                'End If

            Else
                'if the date the user entered is not found
                ' tell user the date was not found
                MsgBox(" The date, that you entered was not found!")
            End If
            Exit For

        Next
        MessageBox.Show(message)


    End Sub

the problem is that the program is telling me that the date the user entered is not found,but, the messagebox is saying it is there.?

Rdgs.
Michael

Why do you need a new form to do the search?

On the same form "form1" fill the dataset in a dataview "MyDataView", then bind the datagrid to this dataview.

Add a textbox to search the date, we will call it "txtDateSearch".

Now after filling this textbox and pressing search you can apply the rowfilter method for the dataview so the datagrid will automatically be filtered.
ex: MyDataView.rowfilter="date ='" & me.txtDateSearch.text & "'"

Instead of the date textbox you can use a datetimepicker.
I hope this helps.

Member Avatar for westsiderailway

Thanks for you reply.....
have been doing some searching , all over the web....

Have finely got my program to work, at least the first row...hehehe

Inline Code Example HerePublic Class Form2_DisplayDB

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

    If TextBox8.Text = "" Then
        MsgBox("ERROR, You Must INPUT a Date to Begin a SEARCH")

    End If

    Dim DGVstr As String = ""
    Dim Search As String = TextBox8.Text

    For Each rowCount In Form1.PetrolCostsT1DataGridView.RowCount.ToString

        'Find the date that the user entered
        'The line below will chop of the time part
        DGVstr = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(1).Value.ToString

        'Textbox9.text should now have only that date part
        TextBox9.Text = Microsoft.VisualBasic.Left(DGVstr, 10)

        'Check to see if the data the user entered is the same as what is in Textbox9
        If TextBox9.Text = TextBox8.Text Then

            ' if the date the user entered is found
            'send cells of current row to Textboxes

            Dim DateString As String = Microsoft.VisualBasic.Left(Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(1).Value.ToString, 10)
            TextBox1.Text = DateString

            TextBox2.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(2).Value.ToString
            TextBox3.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(3).Value.ToString
            TextBox4.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(4).Value.ToString
            TextBox5.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(5).Value.ToString
            TextBox6.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(6).Value.ToString
            TextBox7.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(7).Value.ToString
        Else
            TextBox9.Text = Form1.PetrolCostsT1DataGridView.CurrentRow.Cells(1).Value.ToString

            'if the date the user entered is not found
            ' tell user the date was not found
            MsgBox(" The date, that you entered was not found!")
        End If

        TextBox10.Text = Search
        TextBox11.Text = rowCount


    Next



End Sub

Can someone help me to continue through the datagridview, as if i try to search any other row, it say not found.
i think i have a problem with the looping...

Many thanks.

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.