7 Replies - 6769 Views - Last Post: 01 February 2009 - 06:35 AM Rate Topic: -----

#1 gloring  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-January 09

Need help on VB search form

Post icon  Posted 26 January 2009 - 07:57 AM

Hi,

I was trying to create a search form in visual basic and am struck with a problem.
Can some please help me get out.

I am using the following video procedure to create the form in Vb, but actualy the video is on Visual studio.

http://msdn.microsof...c/bb466226.aspx

When i Create the Query after the Datagrid, I was not getting the text box.
So, when i run the program it is loading the whole data not filtering it.

I created the Text box there manually and giving the text there but it is not working.

Can some onbe please tell me how to send the text to the query that is bulit in the table adapter.

Please also let me know if there is any other way to do this.

Thanks for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help on VB search form

#2 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Need help on VB search form

Posted 26 January 2009 - 08:13 AM

Hi Gloring

I think I know what you are trying to do the code below is what i use to query the dataset, you will see that I am using a combobox and a textbox however the query in the dataset needs to be related to this.



Try
				Me.ToolTableAdapter.Fill(Me.Toolsdataset.Tool, ComboBox1.Text, MaterialTextBox.Text)
			Catch ex As System.Exception
				System.Windows.Forms.MessageBox.Show(ex.Message)
			End Try



Have a look at this Tut it may help


http://www.dreaminco...wtopic74114.htm

Sorry if this is not what you are looking for but you really should post code so that we can see what is going on
Was This Post Helpful? 0
  • +
  • -

#3 gloring  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-January 09

Re: Need help on VB search form

Posted 26 January 2009 - 10:14 AM

Hi,

Thank you so much for the reply.
Apologies for not explaining properly.

This is almost the same that i am looking for.....

All I am trying is to create a form like this

http://i43.tinypic.com/24uxld2.jpg

In which when i enter some text and click search it should return the search results. Actually this is done by following the video in the link i gave in my first post.

but my problem is when i did the same i didnt get the text box automatically and so i coudnt enter any text there.

It was actually displaying all the results.

So i created a text box manually, but dont know how to change the code. This is the code I have now...

 Try
			Me.User_DataTableAdapter.FillByName(Me.Data_UserDataSet2.User_Data)

		Catch ex As System.Exception
			System.Windows.Forms.MessageBox.Show(ex.Message)
		End Try




This is automatically generated by the application (didnt make any changes).

and in which FillByName is the table adapter with the SQl:


SELECT [Company Name], [Last Name], [First Name] FROM [User Data] WHERE (Last Name LIKE Last Name + '%') ORDER BY [Company Name]




Could you please help me correct this.
Also if there is any other easy way to do this please let em know.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Need help on VB search form

Posted 27 January 2009 - 08:15 AM

Hi Gloring

The problem you have is your fillbyname is not related to anything so it will just load all the data. There should be at least a reference to a toolstrip textbox.

Try
			Me.User_DataTableAdapter.FillByName(Me.Data_UserDataSet2.User_Data)

		Catch ex As System.Exception
			System.Windows.Forms.MessageBox.Show(ex.Message)
		End Try


I Have recreated what you have done and got it to work fine but if you look at my code you will see that the fill line of code references param1toolstriptextbox.text which is where you would enter your search data on your form.

Me.User_dataTableAdapter.Fill(Me.DataSet1.User_data, Param1ToolStripTextBox.Text)




Full code

Public Class Form1

	Private Sub User_dataBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles User_dataBindingNavigatorSaveItem.Click
		Me.Validate()
		Me.User_dataBindingSource.EndEdit()
		Me.TableAdapterManager.UpdateAll(Me.DataSet1)

	End Sub

	Private Sub FillToolStripButton_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillToolStripButton.Click
		Try
			Me.User_dataTableAdapter.Fill(Me.DataSet1.User_data, Param1ToolStripTextBox.Text)
		Catch ex As System.Exception
			System.Windows.Forms.MessageBox.Show(ex.Message)
		End Try

	End Sub

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

	End Sub
End Class


What I did was to drag the table onto the dataset. Highlight the auto created SQL query right click and select configure.
Open up the query builder and add a ? mark in the lastname column filter. Press ok and finish.


SELECT		Sno, CompanyName, FirstName, LastName
FROM			User_data
WHERE		(LastName = @Param1)



Attached Image

From the data source window drag the table onto your form, you should get a toolstrip with a textbox. Run the app, enter a known name and press fill. Hopefully it should have worked. If you want textboxes instead of a datagrid highlight the table in the dataset and from the dropdown menu select details.

Now i would normally leave this query alone, make another SQL query in the dataet table say (SearchbylastName). I would then add a textbox and a button and load this code to the button and use textbox1 for the searchdata.

Try
			Me.User_dataTableAdapter.searchbylastname(Me.DataSet1.User_data, TextBox1.Text)
		Catch ex As System.Exception
			System.Windows.Forms.MessageBox.Show(ex.Message)
		End Try


Hope you understand all this I was at a loose end

PS your Variable (Like) is ok I just used the question mark for speed :D
Was This Post Helpful? 0
  • +
  • -

#5 gloring  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-January 09

Re: Need help on VB search form

Posted 28 January 2009 - 04:40 AM

Hi,

Thank you so much for your patience.
I tried the same procedures, but i am still not getting it right.
Please see the sample files attached.

Can you please correct this for me.

I know that asking this is too much. but coudnt find an answer for this.

also if possible can you please tell me if it possible to have a button on the form as "Move" and when it is clicked the selected row from the datagrid should be moved to that table and removed from this one.

and popout a msg as THE USER "ABC" had been moved.

Please note that both the data table structures are different. This cannot be changed because the second table is linked to other applications.

This is would be a great help for me.
Thanks a ton.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#6 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Need help on VB search form

Posted 28 January 2009 - 05:08 AM

Hi Goring

I cannot download the zip file for the risk of viruses (No offence) but I have attached the application that I have created (vbexpress 2008) as I have already posted the code in this thread. You need to post the code as other people might be following this thread. As for the move question not sure as I have never had to do it so you are on your own on that one but you really need to sort out your intial problem.

Attached File  searchproblempost.zip (545.78K)
Number of downloads: 278

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#7 gloring  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-January 09

Re: Need help on VB search form

Posted 01 February 2009 - 01:07 AM

Hi,

This is very helpful.

Thank you so much.
Was This Post Helpful? 0
  • +
  • -

#8 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Need help on VB search form

Posted 01 February 2009 - 06:35 AM

My Pleasure :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1