开发者

simple asp.net search

I am trying to add a search box in my page, where I can search the database.

This is the code I have so far

Partial Class Search
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.Eve开发者_如何学CntArgs) Handles Button1.Click

Select [Title]
FROM [Books]
WHERE ([Title].theName LIKE '%' )
RETURN

End Class

Basically I want the search to return any work that appears in the database or close to it.


Well... it looks like you have a lot of ground to cover based on your first attempt. I think it would greatly behoove you to walk through some tutorials/videos on the very basics of data access in ASP.NET. There is some really good stuff here:

http://www.asp.net/web-forms/data

Look over some of the videos at the very bottom of the page "SQL Server 2005 Express for Beginners". After that, I would recommend taking a look at the LINQ videos above that.

To more directly answer the question, I would recommend using a prepared statement/stored procedure if you want to use ADO.NET. I'd be more inclined to hook up a LINQ to SQL DataContext and do something like: yourContext.TargetTable.Where(o => o.SearchField.Contains("string to search")

Neither of those are going to make much sense until you get a basic footing in data concepts though. Be aware this is something that can compromise your entire application if done wrong...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜