Hi!
How do I get my information in the Database to show in a .aspx page?
If I got a rockband starting with the letter B, I want that band to be shown in my .aspx page.
What is the easiest way to accomplish that?
I use C# as programming language.
Best regards
Jonathan
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Dec 2, 2009, 7:07 AM EST
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("You connection String here");
con.Open();
SqlCommand comm = new SqlCommand("select * from YourTableName where Title like 'b%' or Title Like 'B%'", con);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
Hiren SoniRank #694 · 3.5K reputationPosted Nov 30, 2009, 5:09 PM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 30, 2009, 5:14 PM EST
Can you provide me the Your Database Table Structure - what columns you are having in Table so that i can Provide you the code to accomplish your task :)
Jonatan Pettersson3 reputationPosted Nov 30, 2009, 9:47 PM EST
The columns I use is as follow:
Id - here is a rockband represent by a number.
Title - the rockband is represent by the name of the band
Info - information about the band goes here.
Image - the URL is set here to find the image.
The problem I have is that I get the rockband on the letter B to show. But I get all rockbands on the other letters on C, D, E etc to show too.
Any ideas how to fix this problem?
Best regards!
Jonathan
Gaurish Kumar108 reputationPosted Nov 30, 2009, 10:27 PM EST
you can write query like that for fetching the records which starts from character B
SELECT * FROM [TableName] WHERE Title LIKE 'b%'
Hiren SoniRank #694 · 3.5K reputationPosted Dec 1, 2009, 7:04 AM EST