I was wondering, I have 3 types of obects on an aspx page, a datagrid, a dropdown menu, and Text boxes, could someone please give me examples of what I need to put in the code behind to see or pull the data from a SQL database? I have all the components on the page, I just can't get them to display the data I need.. P.S. .Net is confusing..
The closest I got was getting one of the dropdowns to work,
I had to do the following:
1)add this to the web.config file...
2) open the page's code behind.
3) add ( Imports System.Data.SqlClient ) to the very beginning of the page.
4) In Sql Manager, create stored Proc with this code:
CREATE PROCEDURE dbo.list"Trnt"=the name
SET NOCOUNT ON;
Select * From TrainingList =the database table
order by TrnID = the id your sorting by
5) Insert the code below into the page in the page load event process.
'Put user code to initialize the page here
Dim drTrain As SqlDataReader
Dim cmdselect As SqlCommand
Dim conn As SqlConnection
Dim DSN As String = ConfigurationSettings.AppSettings("ConnectString")
conn = New SqlConnection(DSN)
cmdselect = New SqlCommand("listTrnt", conn)
cmdselect.CommandType = CommandType.StoredProcedure
drTrain = cmdselect.ExecuteReader()
ddTraT.DataSource = drTrain
ddTraT.DataTextField = "TrainingType"
ddTraT.DataValueField = "TrnID"
Besides needing examples on what code I need to display values I also have a few questions.
1) do I need to create stored procs for everything that I need to pull data for?
2) do I have to do the same steps for each component?
3) what code do I need to update the data grid?
4) Is there an easier way?
5) why does VB.Net have wizards for putting the objects on the page but no wizards that provide "choices for post back data" or "result sets"?