View Full Version : SIMPLES way to "capture" data from a SQL Query, WITH OUT using code behind?

02-12-2012, 06:47 PM
Hi, can someone tell me what is the SIMPLES way to "capture/display" data from a SQL Query, WITH OUT using code behind? :thumbsup: I.E. i would like to display data from this Query... but i do NOT want a GridView, ListVew, etc... I just want to PUT output ANYWHERE on the "f****** page i choose :D [like is is with Coldfusion ;)]. My SQL Query is below:

ConnectionString="<%$ ConnectionStrings:countryData_ConnectionString %>"
ProviderName="<%$ ConnectionStrings:countryData_ConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM [Country] WHERE ([country_ID] = ?)">
Type="Int32" />

So, say i would like to "capture" for example:




AND place it ANYWHERE on the page... how do i do that?

1) must i use a "LABEL" : <asp:Label ID="country_popu" ruunat="server" /> :confused:
2) can i use: <% Response.Write(Request.QueryString["country_name"]); %> :confused:
3) what is i had TWO SQL Queries on the same page how do i distinguish between the data source, ID?

This was so EASY in Coldfusion...:)

<!--- Check to see if the session variable exists, if not redirect them to the login page --->
<CFIF IsDefined("session.memID") EQUAL "No">
<CFLOCATION URL="../error_login.cfm">

<cfquery datasource="bar" name="admin" dbtype="ODBC">
FROM members
WHERE memID = #Session.memID#

<cfquery datasource="bar" name="address" dbtype="ODBC">
FROM memAddress
WHERE memID = #admin.memID#


<b>Name:</b> #admin.username#<br>

<b>Mailbox Number:</b> #address.mailbox# #address.street# #address.city#<br>




OH, and while i got you here, how do i INSERT data into a datadase... the SIMPLEST way? NO code behind please:eek: I can validate and postback the FORM, now how do i insert the data in my database and redirect the user to a nother page? THANKS A LOT! :D Coldfusion was SIMMMMMMMPLE! when compared to asp.net :mad:


02-12-2012, 06:52 PM
Sorry, all the CF code above did not copy... i fixed it.

02-21-2012, 08:13 AM
Hello All;

I am trying to INSERT data from a form into a MS ACESS Database. I have tested parts of the CODE behind [just inserting data to one table only] and it worked. Now, i would like to improve on it... and this is where i need your help. I would like to insert data to TWO different TABLES with one action/event... IN FACT, i would like to do THREE things:

1. insert the new USER info to the "User table"... hence , creating a new user account.
2. then, RETRIEVE the new user ID
3. then, insert the new user's URL info into the "Url table" INCLUDING the user_ID [this is an Int.] i just retrieved.

4. i and also trying to pass a value that was NOT in the from into the "User table", this is a Integer.

Please REVIEW the code below AND let me know what i need to do to make it work.

Thanks. :D

protected void SubmitURLButton_Click(object sender, EventArgs e)

CountryDataSqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
CountryDataSqlDataSource1.InsertCommand = "Insert into User (user_Approved,user_FirstName,user_LastName,user_Email,user_Country) VALUES ('1', @user_FirstName, @user_LastName, @user_Email, @user_Country, @user_City)";

CountryDataSqlDataSource1.InsertParameters.Add("user_FirstName", YourFirstNameTextBox.Text);
CountryDataSqlDataSource1.InsertParameters.Add("user_LastName", YourLastNameTextBox.Text);
CountryDataSqlDataSource1.InsertParameters.Add("user_Email", YourEmailTextBox.Text);
CountryDataSqlDataSource1.InsertParameters.Add("user_Country", YourCountryDropDownList1.Text);
CountryDataSqlDataSource1.InsertParameters.Add("user_City", YourCityTextBox.Text);


YourFirstNameTextBox.Text = "";
YourLastNameTextBox.Text = "";
YourEmailTextBox.Text = "";
YourCountryDropDownList1.Text = "";
YourCityTextBox.Text = "";

//Pull new user ID from the USER TABLE
subCategoryDataSqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
subCategoryDataSqlDataSource1.InsertCommand = "Insert into url (url_user_ID,url_SiteName,url_Description,url_URL,url_Category) VALUES (@url_user_ID, @url_SiteName, @url_Description, @url_URL, @url_Category)";

subCategoryDataSqlDataSource1.InsertParameters.Add("url_SiteName", WebsiteNameTextBox.Text);
subCategoryDataSqlDataSource1.InsertParameters.Add("url_Description", WebsiteDescriptionTextBox.Text);
subCategoryDataSqlDataSource1.InsertParameters.Add("url_URL", WebsiteURLTextBox.Text);
subCategoryDataSqlDataSource1.InsertParameters.Add("url_Category", subCategoryDropDownList2.Text);


WebsiteNameTextBox.Text = "";
WebsiteDescriptionTextBox.Text = "";
WebsiteURLTextBox.Text = "";
subCategoryDropDownList2.Text = "";