Unanswered: populate text box from database on page load
I've found all kinds of info on displaying data with various gridview, listview, dataview, etc. controls. What I cannot find is info on how to manually display the data without using a control. I was able to find this type of info for inserting data, i.e. "insertcommandtype" and "insertparameters" and made a working manual input form, but to display the data I'm coming up blank. I'm a rookie at this...I've learned a lot on my own...the internet is an endless resource, but I think maybe what I'm looking for is "outdated" i.e. why do it the hard way, manually, when it can be automated. So, what I'm looking for is simply how to retrieve the data and then display it in an aspx page. This is what I've been trying in my code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim SqlDataSource1 As New SqlDataSource()
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("BarbConnec tionString").ToString()
SqlDataSource1.SelectCommand = "Select * from BarbDatabase" 'Tried this on it's own
SqlDataSource1.SelectParameters.GetValues(HttpCont ext.Current, SqlDataSource1)
'SqlDataSource1.SelectParameters.GetValues(SqlData Source1) 'Header')
and multiple variations of this (Header is the name of one of the db fields)
I normally do it programmatically in the code behind. Basically I query the database, create an instance of the DataSet object, fill the object, and then set the value of the appropriate DataSet column to the Text box.
This post will give you an idea of what I mean. The last line of code before the End Function is where the text box value is set from the DataSet column.
The three lines above that assignment are unnecessary and where the OP got into trouble.
Hi SQL DEV,
Thanks for your response. I had a look at that link and tried to figure out how to incorporate the info into my code. No joy. I tried creating datasets in the code as per the example. I tried creating them in the VWD IDE. I tried all kinds of things. No joy. I tried this code:
HeaderTextBox.Text = ("Header") 'This fills the textbox with the actual word Header
and as the comment says it actually populated the textbox. But in all my trials I just can't get the sql data to populate. My question then is: Do I need to delve deeper and learn datasets and datatables and tableadapters or is there one little simple piece of code I can put in HeaderTextBox.Text = (HERE) to make this work? I plan on doing the former, just not at this time.
FYI: I'm just making a little personal site and don't plan on making any great huge database driven, e-commerce site that will wash the dishes and gas up your car. i.e. I'm trying to keep it as simple as possible.