Another Sql Problem!

adi_uk

Member
Joined
Mar 22, 2006
Messages
12
Programming Experience
1-3
Sorry guys, its me again. Im try to create a search, so the value of what is entered is compared to the information in the databse and the values that match reurned and display in the list. Now, if i use any of the number values as my search criteria they work - e.g id,Tracks etc.

However, if i use title which i want to use in the search criteria, i get an error message

"Data type mismatch in criteria expression."


Here is the code im trying to get to work. The artist value is stored as text in the database.

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]search = TextBox11.Text
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myConnection [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbConnection(myConnectionString)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myCommand [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand("Select * from CDList where Title=" & search, myConnection)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myDataAdapter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbDataAdapter(myCommand)
myConnection.Open()
myDataAdapter.Fill(myDataSet, "CDList")
ObjectList1.AutoGenerateFields = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]ObjectList1.DataSource = myDataSet
ObjectList1.DataBind()
myConnection.Close()
ActiveForm = Form2
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
Label3.Text = "Error reading database" & ex.Message
ActiveForm = Form2
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE]
 
Assuming for a moment that Title is a string based field... .you need tick marks around your string being searched.

VB.NET:
OleDbCommand("Select * from CDList where Title='" & search & "'", myConnection)

-tg
 
Back
Top