1 Replies - 694 Views - Last Post: 29 May 2009 - 12:31 PM Rate Topic: -----

#1 Saravanan07  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-May 09

Error with SQL statement while querying the DB

Posted 28 May 2009 - 11:32 PM

Hello, I have some sql statement error while querying the DB and to display the result on a data grid view. Could someone check the codes below and let me know the problem with the codes. Thank you.

	Dim cm As New System.Data.OleDb.OleDbCommand
	Dim rd As System.Data.OleDb.OleDbDataReader
	Dim Conn As OleDbConnection


Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
		Dim adp As New Data.OleDb.OleDbDataAdapter
		Dim ds As New DataSet
		Dim dv As New DataView

		If txtSearch.Text = Nothing Then
			Call LoadGrid()
			Exit Sub
		Else

			Conn.Open()
			cm.Connection = Conn
			cm.CommandText = "select * from admin_table where admin_Name like '" & txtSearch.Text & "%' OR "
			cm.CommandText = "select * from admin_table where admin_Username like '" & txtSearch.Text & "%'"
			rd = cm.ExecuteReader()
			Conn.Close()

			adp.SelectCommand = cm
			adp.Fill(ds, "dataset")
			dv.Table = ds.Tables(0)
			dv.Sort = "admin_ID"
			gridAdmin.DataSource = dv
			gridAdmin.Refresh()
		End If
	End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Error with SQL statement while querying the DB

#2 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: Error with SQL statement while querying the DB

Posted 29 May 2009 - 12:31 PM

Hello,
are you trying to get the data if the admin_Name is like *** or admin_Username is like ***
if it so?,your select statement is wrong
just type it as you say it
select * from admin_table where admin_Name like '" & txtSearch.Text & "%' OR admin_Username like '" & txtSearch.Text & "%'"


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1