Hello...

I have form having a button and a gridview. The gridview is ok and generates data.

But now, i want to populate only the data when i click on the button specified. Can anybody please help me with this ??

Here is my code :

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

Try
'MsgBox("Open")
cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
cn.Open()
cmd = New OleDbCommand("select partname,partdesc,partnum,partqty from partno where type='Mechanical' ", cn)
cmd.ExecuteNonQuery()

MsgBox("Your Account Created Successfully ")

Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet1.partno)

Catch myException As Exception

MsgBox("No Record Inserted" + myException.ToString())

Finally
'MsgBox("Closing Connection")

cn.Close()
End Try

But this code gives entire data in the table named partno. I want only those records having type 'Mechanical'. Please help me out as there are 7 such buttons on the form.

Thank You so much !!

First of all you must create a textbox on your form then enter type in text box and change this line of code

com = New OleDbCommand("select partname,partdesc,partnum,partqty from partno WHERE type = '" & textbox1.Text & "'", cn)

Hope this would help you.

Actually i thought of it but there are 7 types of items and a person entering data may not be aware of the types existing. To avoid ambiguity, i need to provide either a button or a combobox.. Combox and datagrid would not b easy to deal with.. So, I opted for button..
Thanks for your suggestion, anyways !! :)

Ok then just change this line you would have the result.
com = New OleDbCommand("select partname,partdesc,partnum,partqty from partno WHERE type = '" & combobox1.Text & "'", cn)

Ohk.. Can you please tell me the exact location ?? Where i have written it, is it correct ?? I am new and so need some guuidance, so aksed !!

Thank you .. :))

Also, any addition o modification to this line ??

Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet1.partno)

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

Try
'MsgBox("Open")
cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
cn.Open()
com = New OleDbCommand("select partname,partdesc,partnum,partqty from partno WHERE type = '" & combobox1.Text & "'", cn) 
cmd.ExecuteNonQuery()

MsgBox("Your Account Created Successfully ")

Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet1.partno)

Catch myException As Exception

MsgBox("No Record Inserted" + myException.ToString())

Finally
'MsgBox("Closing Connection")

cn.Close()
End Try
End Sub

Just replace this code with the previous code

This question has already been answered. Start a new discussion instead.