|
| |
|
|
karthik
Posts: 41 Joined: 8/16/2005 Status: offline
|
search database with the text file uploaded - 12/7/2005 15:13:57
ive a access database with data in two columns. i need to search the database by uploading a text file with data pertaining to four column in the database and to display the results in asp. i could make a search only with one textbox where we can enter only one value with LIKE command. but i need to search with the text file by uploading in asp. eg:name age karim 25 kader 26 here i need to search two names by entering those in text file. is that possible ? plz help me. regards karthik
< Message edited by karthik -- 12/7/2005 15:26:48 >
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/8/2005 11:02:15
Hi Karthik, I'm not sure I fully understand. Is it that you want to upload a text file, and using information in that text file you want to search the Access database? quote:
pertaining to four column in the database I don't understand this bit - why do you mention 4 columns here if your database is 2 columns?
|
|
|
|
karthik
Posts: 41 Joined: 8/16/2005 Status: offline
|
RE: search database with the text file uploaded - 12/14/2005 17:00:33
yes i want to upload a text file, and using information in that text file i want to search the Access database?
|
|
|
|
BeTheBall
Posts: 6359 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: search database with the text file uploaded - 12/14/2005 17:10:32
Why an upload? Are you going to do something with the uploaded file other than search? Perhaps you can explain a little more in depth.
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
karthik
Posts: 41 Joined: 8/16/2005 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 8:40:47
Hi, i need to search the data in database using the text file. i give an example here. The following are the fields in database with values. product price --------- ----- soap 12 shampoo 13 i need to search the prices for both soap and shampoo from single input. i cant do it through input in a textbox so i decided to have a text file wherein i have the following format: product --------- soap shampoo so i need to upload the text file which will search with the values in database(access) and return the results in the screen. i need to search different multiple products rather a single product. i hope it makes clear. plz help me . thanks in advance karthik.b
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 9:47:21
Okey Dokey. To grab things from a text document you will need to "parse" the document. The best way to parse text is to use Regular Expressions - though they aren't always easy to use. Here is an article on using RegExp with VBScript. quote:
i cant do it through input in a textbox Is there any reason for the "can't" ??? Perhaps you could get users to pass the values in a query string - tell them to go to yourpage.asp?product= and add the name of the product, so they put in their address bar yourpage.asp?product=shampoo. Then you can grab the value using the Response object.
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 13:49:48
you can still use a querystring, the user would type in yourform.asp?product=shampoo&product=soap and the following code would output it to the screen. <% For i = 1 To Request.QueryString("Q").Count Response.Write Request.QueryString("Q")(i) & "<br />" Next %> obviously you would do something different to the Response.write. Perhaps put it into another array and do something with that, or <% For i = 1 To Request.QueryString("Q").Count mySQL = "SELECT * FROM Products WHERE ProductId = " & Request.QueryString("Q")(i) & ";" Next cmd.Execute(mySQL) %> Something like that.
|
|
|
|
dpf
Posts: 7121 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 13:54:41
quote:
you can still use a querystring, the user would type in yourform.asp?product=shampoo&product=soap why would the user have to type all that in? why not a drop down and the GET method?
_____________________________
Dan
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 14:12:59
I'd use a page with a list of all the products and a checkbox for each. Tick the box and submit and you get prices. But if you were going to do that you could just put the price of the items on that page too. What's the purpose of the site and who will be using the search output?
|
|
|
|
dpf
Posts: 7121 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 14:16:05
gotcha ( and i can never remember the right words..lol)
_____________________________
Dan
|
|
|
|
karthik
Posts: 41 Joined: 8/16/2005 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 14:46:47
Hi, tell me how to give multiple inputs say around 20 products at a time.but each time this is going to be different. thanks
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 15:01:04
as I said, the only way I can think of to choose from 21000 products in an effective (ie quick) way is to use Ajax. If you have the option of .NET I can help build a page that does this. Otherwise, perhaps a checkboxlist and an alphabet as links to the first letter of what it is you want to pick. Unless anyone else has a good idea? What are you using for this, ASP? And do you know what version of IIS you are using? (if you are)
|
|
|
|
karthik
Posts: 41 Joined: 8/16/2005 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 15:07:25
Hi, i use asp and IIS 6. cud u please tell me the .net code and help me in building it.
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 16:36:26
Yep, no probs. What's the time frame on this?
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/15/2005 19:19:41
Also, can you give me the sql statement that you would like to run eg select productid, productname, productprice from Products where productname = ....
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/16/2005 15:43:29
Karthik, if you could email me I'll send you back the compiled code and some instructions. For the really geeky among you (that means everyone! ) here is the code. I didn't come up with the ajax part, I got that from the Code Project, so here's the code to implement it. This is the web page <%@ Page language="c#" Codebehind="ProductSearchForm.aspx.cs" AutoEventWireup="false" Inherits="karthikweb1.ProductSearchForm" %>
<%@ Register TagPrefix="wcp" Namespace="WCPierce.Web.UI.WebControls" Assembly="WCPierce.Web" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<link href="StyleSheet1.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="InstructionLabel" runat="server">Please type the product to search for here</asp:Label></P>
<table border="0">
<tr>
<td>
<wcp:AutoCompleteTextBox runat="server" id="ProductTxt" OnTextChanged="ProductTxt_TextChanged" ListItemCssClass="ListItem"
ListItemHoverCssClass="ListItemHover" />
<asp:Button id="Button1" runat="server" Text="Button" />
</td>
</tr>
</table>
<asp:Label id="TraceLabel" runat="server" Visible="False"></asp:Label>
<P>
<asp:Label id="ResultsLabel" runat="server"></asp:Label></P>
</form>
</body>
</HTML>
This is the code behind for the above page
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using WCPierce.Web;
namespace karthikweb1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class ProductSearchForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label InstructionLabel;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label ResultsLabel;
protected WCPierce.Web.UI.WebControls.AutoCompleteTextBox ProductTxt;
private string searchterm;
protected System.Web.UI.WebControls.Label TraceLabel;
private string connstring;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
connstring = ConfigurationSettings.AppSettings["connString"];
}
protected void ProductTxt_TextChanged(object s, EventArgs e)
{
Searching search = new Searching( connstring );
search.OrgforAjax(s);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ProductTxt.TextChanged += new System.EventHandler(this.ProductTxt_TextChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//this.ProductTxt.TextChanged += new System.EventHandler(this.ProductTxt_TextChanged);
private void Button1_Click(object sender, System.EventArgs e)
{
decimal price = 0;
searchterm = ProductTxt.Text;
string proc = "select price FROM Products WHERE productname = '" + searchterm + "';";
using ( OleDbConnection conn = new OleDbConnection (connstring) )
{
using ( OleDbCommand cmd = new OleDbCommand( proc, conn ) )
{
conn.Open();
using ( OleDbDataReader dr = cmd.ExecuteReader() )
{
while ( dr.Read() )
{
price = (decimal) dr[0];
}
dr.Close();
ResultsLabel.Text = "Product: " + searchterm + " Price: " + price.ToString( "c" );
}//end using dr
}//end using cmd
}//end using conn
}//end Button1_Click
}//end class
}//end namespace
and this is the Searching class
using System;
using System.Data.OleDb;
using WCPierce;
using WCPierce.Web;
using WCPierce.Web.UI.WebControls;
namespace karthikweb1
{
/// <summary>
/// Summary description for Searching.
/// </summary>
public class Searching
{
private OleDbConnection conn = null;
public Searching(string conn)
{
this.conn = new OleDbConnection(conn);
}
public void OrgforAjax(object s)
{
OleDbDataReader dr = null;
try
{
AutoCompleteTextBox act = s as AutoCompleteTextBox;
string searchterm = act.Text;
int length = searchterm.Length;
string proc = "select ProductName from Products where LEFT(ProductName," + length.ToString() + " ) = '" + searchterm + "' ORDER BY ProductName";
OleDbCommand cmd = new OleDbCommand(proc, conn);
conn.Open();
dr = cmd.ExecuteReader();
act.DataSource = dr;
act.DataTextField = "ProductName";
act.BindData();
}//end of try
catch(Exception ex)
{
CallBackHelper.HandleError( ex );
}//end of catch
finally
{
dr.Close();
conn.Close();
}//end of finally
}//end of OrgforAjax
}//end of class
}//end of namespace
oops! Almost forgot the web.config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!-- PUT YOUR CONNSTRING HERE IN THE VALUE ATTRIBUTE!!! -->
<add key="connString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\docs\db3.mdb"/>
<add key="AutoCompleteTextBox.ScriptPath" value="~\scripts\AutoCompleteTextBox.js" />
</appSettings>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to enable ASPX debugging. Otherwise, setting this value to
false will improve runtime performance of this application.
Set compilation debug="true" to insert debugging symbols (.pdb information)
into the compiled page. Because this creates a larger file that executes
more slowly, you should set this value to true only when debugging and to
false at all other times. For more information, refer to the documentation about
debugging ASP.NET files.
-->
<compilation
defaultLanguage="c#"
debug="true"
/>
<!-- CUSTOM ERROR MESSAGES
Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.
Add <error> tags for each of the errors you want to handle.
"On" Always display custom (friendly) messages.
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not running
on the local Web server. This setting is recommended for security purposes, so
that you do not display application detail information to remote clients.
-->
<customErrors
mode="RemoteOnly"
/>
<!-- AUTHENTICATION
This section sets the authentication policies of the application. Possible modes are "Windows",
"Forms", "Passport" and "None"
"None" No authentication is performed.
"Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to
its settings for the application. Anonymous access must be disabled in IIS.
"Forms" You provide a custom form (Web page) for users to enter their credentials, and then
you authenticate them in your application. A user credential token is stored in a cookie.
"Passport" Authentication is performed via a centralized authentication service provided
by Microsoft that offers a single logon and core profile services for member sites.
-->
<authentication mode="Windows" />
<!-- AUTHORIZATION
This section sets the authorization policies of the application. You can allow or deny access
to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
(unauthenticated) users.
-->
<authorization>
<allow users="*" /> <!-- Allow all users -->
<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page within an application.
Set trace enabled="true" to enable application trace logging. If pageOutput="true", the
trace information will be displayed at the bottom of each page. Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your web application
root.
-->
<trace
enabled="false"
requestLimit="10"
pageOutput="false"
traceMode="SortByTime"
localOnly="true"
/>
<!-- SESSION STATE SETTINGS
By default ASP.NET uses cookies to identify which requests belong to a particular session.
If cookies are not available, a session can be tracked by adding a session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
/>
</system.web>
</configuration>
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/16/2005 18:30:28
I've sent you the files and instructions, but here's some general ones. .NET uses pre-compiled code, you can't just put the code into a page and run it without the dll's. If you don't have something like Visual Studio, then download the .NET SDK. Then you can use the command line compiler to compile the code. Type into the compiler csc NameOfFileToCompile.cs and press enter. Take the dll that has been compiled and put it in a dir called Bin that is in the main website dir. Also put the web.config into the directory - it holds useful settings, like the .dat files you used to get pre Win2000. You'll also need to get the code from the link I gave, and put the javascripts either directly in the page or in a dir called Scripts off of the main dir. If anyone else needs the dlls jsut let me know.
|
|
|
|
yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: search database with the text file uploaded - 12/20/2005 4:36:21
Karthik, did it work?
|
|
|
|
karthik
Posts: 41 Joined: 8/16/2005 Status: offline
|
RE: search database with the text file uploaded - 2/3/2006 6:42:14
plz help me how to run it.
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|