473,789 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select SQL query column

I need to implement a simple search function to lookup order information in
a SQLserver table. The code below works fine for a search to the ³OrderID²
column. However, I¹d like to offer the user the ability to select 3 possible
columns to search from. I added a dropdownlist to select the column. My
question is, how do I dynamically modify the SQL command <String selectCmd =
"select * from Orders where OrderID = @OrderID";> to take the input from the
dropdownlist?
Also, can I assign a different Value to <asp:listitem>O rder
ID</asp:listitem> than ³Order ID²? I¹d like to display the parameter with a
space but have its Value = OrderID (no space) since that¹s the column name
in the SQL table.
Thank you,
Stephan.
<%@ Page Language="C#" ContentType="te xt/html" ResponseEncodin g="iso-8859-1"
%>
<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.SqlClie nt" %>

<html>
<script language="C#" runat="server">

public void GetOrder(Object sender, EventArgs E)
{
String selectCmd = "select * from Orders where OrderID = @OrderID";

SqlConnection myConnection = new SqlConnection(" server =
'LMM-MB-DATA,25886';Dat abase = 'Oligo_Order'; Trusted_Connect ion=Yes");
SqlDataAdapter myCommand = new SqlDataAdapter( selectCmd,
myConnection);

myCommand.Selec tCommand.Parame ters.Add(new SqlParameter("@ OrderID",
SqlDbType.NVarC har));
myCommand.Selec tCommand.Parame ters["@OrderID"].Value =
SearchString.Te xt;

DataSet ds = new DataSet();
myCommand.Fill( ds, "Orders");

MyDataGrid.Data Source= ds.Tables["Orders"].DefaultView;
MyDataGrid.Data Bind();
}

</script>

<body style="font: 10pt verdana">

<form runat="server">
<p> Search previously placed order by:
<asp:dropdownli st ID="SearchSelec t" runat="server">
<asp:listitem>O rder ID</asp:listitem>
<asp:listitem>L ast name</asp:listitem>
<asp:listitem>C omments</asp:listitem>
</asp:dropdownlis t>
<asp:textbox id="SearchStrin g" MaxLength="50" runat="server"
TextMode="Singl eLine" />
</p>

<input type="submit" OnServerClick=" GetOrder" Value="Get Orders"
runat="server"/><p>

<ASP:DataGrid id="MyDataGrid " runat="server"
Width="700"
BackColor="#ccc cff"
BorderColor="bl ack"
ShowFooter="fal se"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaa add"
EnableViewState ="false"
/>

</form>

</body>
</html>

Nov 17 '05 #1
0 1230

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
5264
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All works as expected. But >>> numb=10 >>> cursor.execute("SELECT * FROM mytest where clientID = %d",numb) Traceback (innermost last): File "<stdin>", line 1, in ?
2
9246
by: Benoit Le Goff | last post by:
Hello. I test some query on sql server 2000 (sp2 on OS windows 2000) and i want to know why a simple query like this : select * from Table Where Column like '%value' is more slow on 2000 than on sql 7. And this case arrive only if the % character is in the begin. If you test this : select * from Table Where Column like 'v%alue'
3
3548
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
1
4294
by: Paul | last post by:
Assume you have two varchar (or Text) columns named L and U which are identical except that the charset for L is latin1 and the charset for U is utf8. All the records in L and U are identical in terms of content, consisting of only 7 bit ASCII characters. Both columns have indexes of the same type (e.g. assume Unique indexes if you want). Here's my question: Will the fact that column U has a utf8 charset make select queries run slower on...
4
2866
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table that links to a transaction items table that links to the products table: (User Table) UserID Other user data
17
5029
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by cust_no, ded_type_cd, chk_no)
3
6472
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
6
4849
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
1
1619
by: steveyell | last post by:
Hi there, I have a database with 90,000 property records and I need to split the database into 5 geographic areas. Those areas are defined by postcode districts, and a number of postcode districts make up an area. I have a column for postcode district and another column for area which is populated. The geographic area is comprised of all the properties in that area, which are already defined by the area column, but is also comprised of...
17
3139
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note that I am using Allen Browne's multi-select list box for a report as a guide. I should also note that my access skills are not the best so I may need some explaining on certain things. First let me give some background on the database: I have a...
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9506
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.