Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Cool SIMPLES way to "capture" data from a SQL Query, WITH OUT using code behind?

    Hi, can someone tell me what is the SIMPLES way to "capture/display" data from a SQL Query, WITH OUT using code behind? 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 [like is is with Coldfusion ]. My SQL Query is below:

    Code:
    <asp:SqlDataSource 
    ID="SqlDataSource1" 
    runat="server" 
        ConnectionString="<%$ ConnectionStrings:countryData_ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:countryData_ConnectionString.ProviderName %>" 
        SelectCommand="SELECT * FROM [Country] WHERE ([country_ID] = ?)">
        <SelectParameters>
            <asp:QueryStringParameter 
            Name="country_ID" 
            QueryStringField="country_ID" 
                Type="Int32"  />
        </SelectParameters>
    </asp:SqlDataSource>
    So, say i would like to "capture" for example:

    "country_name"

    "country_desc"

    "country_popu"

    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" />
    2) can i use: <% Response.Write(Request.QueryString["country_name"]); %>
    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...

    Code:
    <!--- 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">
    </CFIF>
    
    <cfquery datasource="bar" name="admin" dbtype="ODBC">
    	SELECT		*
    	FROM 		members
    	WHERE 		memID = #Session.memID#
    </cfquery>
    
    <cfquery datasource="bar" name="address" dbtype="ODBC">
    	SELECT		*
    	FROM 		memAddress
    	WHERE 		memID = #admin.memID#
    </cfquery>
    
    
    <body>
        <cfoutput>
    
    	<b>Name:</b> #admin.username#<br>
    
            <b>Mailbox Number:</b> #address.mailbox# #address.street# #address.city#<br>
       
        </cfoutput>  
    
    </body>
    Thanks...

    OH, and while i got you here, how do i INSERT data into a datadase... the SIMPLEST way? NO code behind please 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! Coldfusion was SIMMMMMMMPLE! when compared to asp.net

    THANKS...
    Last edited by robuc; 02-12-2012 at 06:54 PM. Reason: Sorry, all the CF code above did not copy... here it is: [its not needed, but]

  • #2
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Sorry, all the CF code above did not copy... i fixed it.
    Last edited by robuc; 02-12-2012 at 06:56 PM.

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Cool How to INSERT data into TWO separate Tables at the same time.

    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.

    Code:
    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);
    
                CountryDataSqlDataSource1.Insert();
    
                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);
    
                        subCategoryDataSqlDataSource1.Insert();
                      
                        WebsiteNameTextBox.Text = "";
                        WebsiteDescriptionTextBox.Text = "";
                        WebsiteURLTextBox.Text = "";
                        subCategoryDropDownList2.Text = "";
    
                    }
                }
    
    
            }
      
        }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •