tags:

views:

204

answers:

6

Hiya all,

I've connected to database, using data set .xsr now I wan't to extract all rows in my table. Here is my table structure :

Lastname
Address
zipcode
city
country
email

So here is one example of table row entry :

Danish Morten Olsen 58b 82341 Kobenhavn Denmark [email protected]

Now I'd like for someone to tell me how can I extract this info for all entries in the table in format :

<tr>
   <td>Lastname</td>
   <td>Address</td>
   <td>zipcode</td>
   <td>city</td>
   <td>country</td>
   <td>email</td>
</tr>

where of course one html table row represents one table row in database, I'm a newbie just two days ago installed necessary tools, database and started programming asp <% %>(asp noob yes, programming noob no) .. this is important so please answer if you can spare time .

thank you

+1  A: 

Have a look at: http://www.learnasp.com/freebook/asp/dbsimple.aspx

If you've just started learning ASP, you should rather start having a look at ASP.NET.

Mark Redman
A: 

Your post led me to believe you were coding in Classic ASP, as opposed to ASP.NET. I recommend that you get started by watching some of the videos over on asp.net/learn. Start with this one on how to get data out of the database using a DataSet and Gridview by creating a data access layer (DAL) in your app. Optionally, you could read the HTML version of the tutorial.

Dan Lynn
A: 

Thank you for your post but I just can't find the right answer .. so let me show you how would I do that in PHP ,

 //PHP
 mysql_connect("localhost", "User", "sdaSEAD#%1sjkadwqW#!"); //connect
 mysql_select_db("project");  //choose database
 $query = mysql_query("SELECT * FROM data"); //choose what you need from the table
 //PHP & HTML
 while($row = mysql_fetch_array($query)) //keep going until there are rows to select
{
extract($row);   //extract them
echo "<tr><td>$lastName</td><td>$address</td><td>$zipcode</td><td>$city</td>$country</td><td>$email</td></tr>";
}

Sorry guys I've read and seen so many tutorials that I'm feeling sick of it all, now is there a simple-straightforward way to translate this into asp without adding the unnecessary complexion to this .. just connect to the database using windows authentication and extracting the whole content of the database. Thank you

c0mrade
and you should be editing your own original post instead of posting new "dummy" answers
marc_s
A: 

I never use asp but I did same thing in JSP, I just came across the link

http://www.powerasp.com/content/database/using%5Fselect.asp

This would probably help your using asp.

GG
+1  A: 

Standard ASP.NET Webforms (which is what I guess you'll be using) doesn't give you total control over your HTML - you're not programming directly in HTML and markup, but against an abstracted "webform" model. E.g. you use and create server-side objects like data source (to grab your data), a gridview etc. - and the server control then really renders out the HTML to be sent back to the customer's browser.

So you might have a SQL data source to reach into your SQL Server table and grab the data:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:TestConnectionString2 %>" 
    SelectCommand="SELECT [Lastname], [Address], [zipcode], [city], 
                          [country], [email] FROM [Addresses]">
</asp:SqlDataSource>

and then hook that up to a data-bound ListView on your ASP.NET form:

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
  <ItemTemplate>
    <span style="background-color: #E0FFFF;color: #333333;">Lastname:
    <asp:Label ID="LastnameLabel" runat="server" Text='<%# Eval("Lastname") %>' />
    <br />
    Address: <asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' /><br />
    zipcode: <asp:Label ID="zipcodeLabel" runat="server" Text='<%# Eval("zipcode") %>' /><br />
    city: <asp:Label ID="cityLabel" runat="server" Text='<%# Eval("city") %>' /><br />
    country: <asp:Label ID="countryLabel" runat="server" Text='<%# Eval("country") %>' /><br />
    email: <asp:Label ID="emailLabel" runat="server" Text='<%# Eval("email") %>' />
    <br /><br /></span>
  </ItemTemplate>
  <EmptyDataTemplate>
    <span>No data was returned.</span>
  </EmptyDataTemplate>
  <LayoutTemplate>
     <div ID="itemPlaceholderContainer" runat="server" 
          style="font-family: Verdana, Arial, Helvetica, sans-serif;">
        <span ID="itemPlaceholder" runat="server" />
     </div>
     <div style="text-align: center;background-color: #5D7B9D;
                 font-family: Verdana, Arial, Helvetica, sans-serif;color:#FFFFFF;">
     </div>
   </LayoutTemplate>
 </asp:ListView>

Check out the official ASP.NET website which has plenty of articles, tutorials, screen casts and demos on how to get started on ASP.NET webform development.

If you want total control over your markup, you should check out ASP.NET MVC which is a new concept for ASP.NET developers, but which might be a lot more along the lines of what you already know from PHP programming. Here, you do have total control over your HTML and every bit and byte being sent back to the browser.

Marc

marc_s
A: 

wanna refresh this post

c0mrade