Reputation: 13769
I have loaded my database with one table under "Data Connections" in the "Server Explorer" pane.
What is the standard / best-practices way to handle a simple query in a VB ASPX page?
My left <div>
would be a set of form elements to filter rows, and when the button is clicked, the main <div>
would show the columns I want for the rows returned.
Note: Answers in C# are okay too, I'll just translate.
Upvotes: 2
Views: 10575
Reputation: 25359
Presuming web forms you would have a data control, such as a gridview or repeater, bound to a datasource (such as SqlDataSource or ObjectDataSource etc). You would then bind the parameters of your filter controls as control parameters of your datasource. You then need a button to fire a postback and that's basically it.
See Filtering Data Using Data Source Controls for more detail.
Upvotes: 1
Reputation: 38392
There are lots of approaches to this and what is "best" depends on your scenario. This might be a good starting point for you to try doing this with a gridview:
Upvotes: 0
Reputation: 245489
<%
using(SqlConnection conn = new SqlConnection(someConnectionString))
{
SqlCommand command = new SqlCommand("select * from table", conn);
DataTable results = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(command);
conn.Open();
adapter.Fill(results, command);
}
// You can work with the rows in the DataTable here
%>
Would work if you're trying to do everything in the page code.
I would suggest using the Code-Behind file and working with code that way. It makes things easier to understand when your code is in a seperate file leaving markup in one spot and code in the other.
Upvotes: 3