AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 nested queries in gridview
Posted by julien_h on  6/30/2009 4:13:58 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hello ,
I'm julien , beginner in visual studio 2008 using c# language

I Have this task that I seem to be stuck in !

I've created a database using sql server express 2005 of 4 tables :"BOOKS , AUTHORS , CATEGORIES and PUBLISHERS ".

I've connected this database to my gridview in visual studio , it shows me all the books like this : " BOOK publisher , TITLE, CATEGORY "

the problem is that my task is to show what every author has in terms of books .
and I cant figure out how to do that !!!!

can u tell me if any of this code that I'm using is helpfull or not ???

if it is what's missing ???????????????????



public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (!this.IsPostBack)
{


string ConnectionString ="Data Source=----------;Initial Catalog=julien;Integrated Security=True";
string selectSQL = "SELECT [category], [title], [publisher] FROM [books JOIN AUTHORS] ORDER BY [title], [category], [publisher]" GROUP BY [author name ];



System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("julienCS");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(selectSQL, con);
System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(cmd);
DataSet ds = new DataSet();

adapter.Fill(ds, "BOOKS ");

GridView1.DataSource = ds;
GridView1.DataBind();
}
}
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
if (!this.IsPostBack)
{

string ConnectionString = "Data Source=DELL-FF646ED476;Initial Catalog=julien;Integrated Security=True";
string selectSQL = "SELECT DISTINCT [category], [title] FROM [books] ORDER BY [title], [category] WHERE [AUTHOR ID = X]";
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("julienCS");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(selectSQL, con);
System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(cmd);
DataSet ds = new DataSet();



adapter.Fill(ds, "books ");

GridView2.DataSource = ds;
GridView2.DataBind();

}
}
}



any help will be much appreciated !!! It's kinda urgent !



I want it to look somth like this:

author : elieeee
-----------------------------------------
book category book title
-----------------------------------------
comedy love
action woooow
drama I hate u


Post Your Reply Post New Question

 Viewer's Reply
This Question has 0 replies.

 
Sponsored by
Everything You Know About CSS Is Wrong! - Free 37 Page Preview!
SearchSAP
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter