3 Replies - 1764 Views - Last Post: 19 April 2010 - 06:50 PM Rate Topic: -----

#1 eddiehm  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 09-March 10

inserting data into a input box from an sql statment

Posted 19 April 2010 - 10:25 AM

When it come to asp I am a novice at best but I am having some trouble with trying to input data into a text box from a sql statement. my instructor says I should just use a gridview. personal I think it looks tacky if someone could help me out on this I would be very grateful.


<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sqlclient" %>
<%@ Import Namespace="System.Text" %>
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        
        groupname.Text = Request.QueryString("groupname")
        
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:evanConnectionString %>" 
         SelectCommand="SELECT * FROM groups WHERE id = @groupid" >
        
        </asp:SqlDataSource>
    Group Name:<br />
    <asp:TextBox ID="groupname" runat="server"></asp:TextBox>
    <br />
    Date:<br />
    <asp:TextBox ID="ddate" runat="server" ></asp:TextBox>
    <br />
    Time:<br />
    <asp:TextBox ID="dtime" runat="server"></asp:TextBox>
    <br />
    Test Time:<br />
    <asp:TextBox ID="ttime" runat="server"></asp:TextBox>
    <br />

    Location:<br />
    <asp:TextBox ID="location" runat="server"></asp:TextBox>
    <br />
    Test Location:<br />
    <asp:TextBox ID="tlocation" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Button ID="submit" runat="server" Text="Edit Group" />
    
</asp:Content>









Thanks in advance for any help you can give me.

Is This A Good Question/Topic? 0
  • +

Replies To: inserting data into a input box from an sql statment

#2 keakTheGEEK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 107
  • View blog
  • Posts: 344
  • Joined: 23-February 10

Re: inserting data into a input box from an sql statment

Posted 19 April 2010 - 01:20 PM

You have the line of code where you are requesting a value in the querystring, but I did not see anywhere else in your code where you send the data to the querystring. You need a statement like the following:
Response.Redirect([url].aspx?groupname=[value]);



Looks like your are generating the data on the same page that you want to read it, so you can fill in the url place holder with your page name. Here's a more detailed example on how to use querystring in ASP .NET.

This still isn't going to solve your problem because you have a datasource declared and configured, but you aren't actually executing the query. If you are going to take the approach you are taking you need to execute the command against your datasource and store the record results in some kind of object. Read up on ASP .NET Data Access, I think you will find this information very useful.


Honestly, a gridview approach (which your instructor suggested) would be a much better approach to take in my opinion. There are other options as well (e.g. details view, form view, etc). You can then easily use bind()/eval() methods to populate your controls. Also, they are highly customizable when it comes to formatting the way they look. Hope this helps.

GOOD LUCK!
Was This Post Helpful? 0
  • +
  • -

#3 eddiehm  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 09-March 10

Re: inserting data into a input box from an sql statment

Posted 19 April 2010 - 04:04 PM

the querystring was actually just for trouble shooting I was making sure I was passing a value through the url I had forgotten to remove that from the code. Sorry about that. But thanks for the links I will definitely be going over it to try and figure this out.
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: inserting data into a input box from an sql statment

Posted 19 April 2010 - 06:50 PM

You have one of two ways you can go about this. You can query for the data from the database in your code behind and then assign the values to the correct textbox.

Or you could use the SqlDataSource that you have in your code currently and then you will need a control that you can bind it to for the data.

I would suggest looking into using the DataList control where you can layout your textboxes in the Template and then bind directly to them from the data source. See the link for an example.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1