Querying a database (Ms Access)

I'm trying to select a query on the database where by it uses like

Page 1 of 1

5 Replies - 6643 Views - Last Post: 09 January 2007 - 12:11 AM Rate Topic: -----

#1 zoe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 07

Querying a database (Ms Access)

Posted 08 January 2007 - 06:43 AM

Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
		'The OleDbDataReader is a forward-only data reader used for speed and efficiency.
		Dim SQLReader As OleDbDataReader
		'Dim Searchstr As String = ""
		Dim Searchstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\NRaqa\Desktop\TestD.mdb"
		Dim conn As OleDbConnection

		conn = New OleDbConnection(Searchstr)

		Dim query As String = "Select NAME FROM KonkeQuery where NAME like '%storename.text%'"

		Dim command As New OleDbCommand(query, conn)

		If storename.Text = "" Then
			MsgBox("Please Enter Strore name", MsgBoxStyle.Exclamation)
			Exit Sub
		Else
			conn.Open()
			SQLReader = command.ExecuteReader()


			If SQLReader.HasRows Then
				While SQLReader.Read

					storename.Text = SQLReader.Item(query)
				End While
			Else
				MsgBox("There were no matches found, please try again", MsgBoxStyle.Information)
			End If

			conn.Close()
		End If


	End Sub



I'm trying to select a query on the database where by it uses like ie. '%storename.text%.. i want it to display all the storenames with the entered data so that i can select which eva 1 i want

Thanks in advance

Regards
Noks

Is This A Good Question/Topic? 0
  • +

Replies To: Querying a database (Ms Access)

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Querying a database (Ms Access)

Posted 08 January 2007 - 07:53 AM

Can you describe the problem you are encountering? Is it generating an error message?
Was This Post Helpful? 0
  • +
  • -

#3 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: Querying a database (Ms Access)

Posted 08 January 2007 - 10:57 AM

Looks like you are trying to grab the data, and put the last one found into the text box. Is this correct? If not, are you wanting to maybe add the values to a drop down box or display in a data grid? You may end up getting an error when you are retrieving the data because when you get the data back, you should be retrieving the data from the index of the column number that you want (in this case 0, there is only one field being returned, so column (or field) 0 would be the only valid one) instead of using the query string again.
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Querying a database (Ms Access)

Posted 08 January 2007 - 11:36 AM

You need to concatenate the information form your textbox into the SQL statement.
Dim query As String = "Select NAME FROM KonkeQuery where NAME like '%" & storename.text & "%'"


Was This Post Helpful? 0
  • +
  • -

#5 zoe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 07

Re: Querying a database (Ms Access)

Posted 08 January 2007 - 11:24 PM

Thanks guys (u've been a huge help).. the problem has been solved... Now i wanna mark dis issue as done & don't know how to... Anyhelp on that pls

Regards
Noks
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Querying a database (Ms Access)

Posted 09 January 2007 - 12:11 AM

You just did it. Leave the posts as they are so that other members can benefit from your solution if they are having a similar problem.

Glad you were able to resolve the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1