Please help and thank you!
Newbie Phil
Actual Code Begins here:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb"
Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<% Dim myVariable As String
myVariable = "c"
%>
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT ContactName FROM Customers WHERE
(ContactName LIKE N'%<%myVariable %>%')">
</asp:SqlDataSource>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ContactName" HeaderText="ContactName"
SortExpression="ContactName" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
"Phillip Vong" <phillip_vong*at*yahoo*dot*com> wrote in message
news:u9J0XFfV...@TK2MSFTNGP12.phx.gbl...
I did do it just like you said where I put '%Varible%' but the Where
statement actually thinks I'm using the word Variable versus looking at the
variable.
Please help.
"Patrick.O.Ige" <naija...@hotmail.com> wrote in message
news:OIb3cShV...@tk2msftngp13.phx.gbl...
<asp:SqlDataSource id="myDataSource" runat="server"
ConnectionString="..."
SelectCommand="SELECT Column1, Column2 FROM table WHERE key =
@MyKeyName">
<SelectParameters>
<asp:Parameter Name="MyKeyName" DefaultValue="SomeValue" />
</SelectParameters>
</asp:SqlDataSource>
You can use a ControlParameter to bind the value to a control, a
QueryStringParameter to bind the value to a query string field, or just
use bog-standard Parameter and set the value yourself.
Best place to do that is in Page_Load if your value won't change eg.
if( ! Page.IsPostback)
MyDataSource.SelectParameters["MyKeyName"].DefaultValue =
TheUserBrowsingThisPage.UserId;
Or in the SqlDataSourceSelecting event if you want to change it
dynamically for each select.
Futher info here
http://msdn2.microsoft.com/en-us/library/z72eefad(VS.80).aspx
and here
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.sqldatasource.selecting(VS.80).aspx
HTH. But you should still prefer stored procedures, or at least keeping
your SQL in a data access class.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Show me your certification without works,
and I'll show my certification
*by* my works.
"Phillip Vong" <phillip_vong*at*yahoo*dot*com> wrote in message
news:u9J0XFfV...@TK2MSFTNGP12.phx.gbl...