ASP.NET Querying a database

  • Thread starter Thread starter Mark Thomson
  • Start date Start date
M

Mark Thomson

In my .aspx file i have:

<form runat="server">
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
runat="server"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="select authorname from authors where authorid = authorid"
ConnectionString="<%$ ConnectionStrings:Pubs %>" />
</form>


I have this code to run a query on the database.

The trouble is I don't know how to embed an authorid which is in my textbox
into the query.

in my .aspx.cs file i have:

protected void getAuthor_Click(object sender, EventArgs e)

{


}



How can i change the query so that i embed the authorid that i have got from
my textbox ?
 
Use <asp:ControlParameter> in the .aspx page. In the code-behind,
SqlDataSource.SelectParameters collection.

In my .aspx file i have:

<form runat="server">
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
runat="server"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="select authorname from authors where authorid = authorid"
ConnectionString="<%$ ConnectionStrings:Pubs %>" />
</form>


I have this code to run a query on the database.

The trouble is I don't know how to embed an authorid which is in my textbox
into the query.

in my .aspx.cs file i have:

protected void getAuthor_Click(object sender, EventArgs e)

{


}



How can i change the query so that i embed the authorid that i have got from
my textbox ?
 
Back
Top