ASP.NET Querying a database

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 ?
 
S

Siva M

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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top