displaying Accessdatasource field in textbox using ASP.Net and VS.Net 2005 ?

Discussion in 'ASP .Net' started by Luqman, Jan 20, 2006.

  1. Luqman

    Luqman Guest

    How can I display any field value in textbox of sqldatasource using VS.Net
    2005 ?

    Say : Dim x as new AccessDataSource
    X.connectionstring="Data source="D:\mydb.mdb"
    X.Selectcommand="Select CompanyName from customers"

    Textbox1.text= ??? <-------- I need to display CompanyName Field in this
    textbox, how can I ?

    Best Regards,

    Luqman
     
    Luqman, Jan 20, 2006
    #1
    1. Advertisements

  2. How many values do you want to put into your TextBox? Your SQL select
    statement will probably return back more than one value.
     
    Christopher Reed, Jan 23, 2006
    #2
    1. Advertisements

  3. Luqman

    Luqman Guest

    Hi,

    I want to display each field in a separate textbox, so if I have 2 fields,
    say, companycode and companyname, I want to display both of them in two
    textboxes.

    For eg.

    Textbox1.text= companycode
    Textbox2.text=companyname

    But I don't know the syntax, Any idea please ?

    Best Regards,

    Luqman
     
    Luqman, Jan 24, 2006
    #3
  4. You might consider using a FormView which is a template-based data control.
    So, within your ASPX page, you could do something like this:

    <asp:FormView id="FormView1" runat="server"
    DataSourceID="AccessDataSource1">
    <ItemTemplate>
    <asp:TextBox id="TextBox1" runat="server" Text='<%#
    Eval("CompanyCode") %>' />
    <asp:TextBox id="TextBox2" runat="server" Text='<%#
    Eval("CompanyName") %>' />
    </ItemTemplate>
    </asp:FormView>
    <asp:AccessDataSource id="AccessDataSource" runat="server"
    ConnectionString = "Data source=D:\mydb.mdb"
    SelectCommand = "Select CompanyCode, CompanyName from customers" />

    Depending your actual set up, you may have to tweak the above a little.
     
    Christopher Reed, Jan 24, 2006
    #4
  5. Luqman

    Luqman Guest

    Ok thanks for your help, I will definitely try out.

    Best Regards,

    Luqman
     
    Luqman, Jan 25, 2006
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.