Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 displaying data

Author  Topic 

sqldennis
Starting Member

2 Posts

Posted - 2010-06-06 : 19:32:20
the case:
im trying to display data from an acces database. the problem however is that, instead of showing all productID's, it shows only 1 productID and its price.
im new to sql and asp.net so im having a hard time getting this done.
im doing this in C#.
i should note that, after i figure this out, the productID's need to be clickable so it will redirect u to that productID's personal page.
in short, a webshop kind of idea.
my code in the aspx.cs currently looks like this, hope u guys can help.


protected void Page_Load(object sender, EventArgs e)
{



OleDbConnection verbinding = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:/LOCATION/mydatabase.mdb");


try
{
verbinding.Open();

if (verbinding.State.ToString() == "Open")
{

string sqlstr = "SELECT ProductID, price FROM Product WHERE Producttype='Jeans'";


OleDbCommand cmd = new OleDbCommand(sqlstr, verbinding);
OleDbDataReader lees = cmd.ExecuteReader();
lees.Read();
Label1.Text = lees["ProductID"].ToString();
Label2.Text = lees["price"].ToString();
lees.Close();


}
}
catch (Exception x)
{
Label1.Text = "Database Error: " + x.Message;
Label2.Text = "Database Error: " + x.Message;
}
finally
{
verbinding.Close();
}

}

expat
Starting Member

7 Posts

Posted - 2010-06-16 : 00:51:23
Try this.

while (lees.Read())
{
Label1.Text = lees["ProductID"].ToString();
Label2.Text = lees["price"].ToString();
}
Go to Top of Page
   

- Advertisement -