Jump to content

display SQL result in ASP.NET


DaveMason
 Share

Recommended Posts

Hello! I'm new to this. This is my first program. I'm trying to search a database and then display a simple result on the same page. Here is what I have done so far. Thanks for help. Note: I'm using NotePad to write my ASP.NET code.<%@ Import Namespace="System.Data.OleDb" %><script runat="server">Sub Search(send As Object, e As EventArgs)dim txtInputdim dbconn, sql, dbcomm, dbreadtxtInput=txtSearch.Textdbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("db1.mdb"))dbconn.Open()sql = "SELECT * FROM dictionary WHERE Word Like '*" & txtInput & "*'; "dbcomm=New OleDbCommand(sql,dbconn)dbread=dbcomm.ExecuteReader()dictionary.DataSource=dbreaddictionary.DataBind()dbread.Close()dbread.Close()End Sub</script><html><body><form id="Form1" runat="server"><asp:TextBox id="txtSearch" runat="server" /><asp:Label ID="txtOutPut" runat="server" /><asp:Button ID="Button1" text="Search" OnClick="Search" runat="server" /></body></html>

Link to comment
Share on other sites

change this

dbread.Close()dbread.Close()

to

dbread.Close()dbconn.Close()

and you do not have dictionary declared. Is it a datagrid?if is do this

<html><body><form id="Form1" runat="server"><asp:TextBox id="txtSearch" runat="server" /><asp:Label ID="txtOutPut" runat="server" /><asp:Button ID="Button1" text="Search" OnClick="Search" runat="server" /><br/><br/><h1>Results</h1><asp:DataGrid id="dictionary" runat="server"/></body></html>

Link to comment
Share on other sites

Thanks for the quick reply.Well, what I'm trying to do is search the reocrd and if it matches the criteria, display the word and definition. that's about it. I'm still unable to get it to work correctly. Is there a new apporach to do it?thanks again.

I personally don't like datagrids unless it is for a very simple output.I like to use the SQLDataReader and cycle through the records and process the output. It gives you total control. Datagrids I find are hard to manipulate.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...