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.
Author |
Topic |
naijacoder
Starting Member
5 Posts |
Posted - 2005-05-08 : 09:48:39
|
HelloI have such a Stored procedure below:-CREATE PROCEDURE webpage AS SELECT * FROM templatesSELECT * FROM linksSELECT * FROM categorySELECT * FROM pagesGOAnd in my application below i'm using the stored procedure but after compiling i get the error "Column 'link_url' does not belong to table links"But if i comment out the string with SQL statement and code the SQL statement in my code it works..it seems my stored procedure isn't seeing the LINKS table.IS MY STORED PROCEDURE CORRECT?:-Any help will be appreciated!-----------------------------void Page_Load(){string csAccess = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];SqlConnection dcAccess = new SqlConnection(csAccess);SqlCommand cmdAccess = new SqlCommand("webpage",dcAccess);cmdAccess.CommandType = CommandType.StoredProcedure;//string ssTemplate = "Select * From templates Where template_id = 1";//string ssLinks = "Select * From links";//string ssCategory = "Select * From category";string ssPage = "";if (Request.QueryString["page"] == null){ssPage = "Select * From pages Where page_id = 1";}else{ssPage = "Select * From pages Where page_id = " + Request.QueryString["page"];}//SqlDataAdapter daTemplate = new SqlDataAdapter(ssTemplate, dcAccess);//SqlDataAdapter daLinks = new SqlDataAdapter(ssLinks, dcAccess);//SqlDataAdapter daCategory = new SqlDataAdapter(ssCategory, dcAccess);SqlDataAdapter daPage = new SqlDataAdapter(ssPage, dcAccess);SqlDataAdapter daTemplate = new SqlDataAdapter(cmdAccess);SqlDataAdapter daLinks = new SqlDataAdapter(cmdAccess);SqlDataAdapter daCategory = new SqlDataAdapter(cmdAccess);//SqlDataAdapter daPage = new SqlDataAdapter(cmdAccess);DataSet dsAccess = new DataSet();DataTable dtTemplate = new DataTable();DataTable dtLinks = new DataTable();DataTable dtCategory = new DataTable();DataTable dtPage = new DataTable();int dtLinksCount;int dtCategoryCount;try{dcAccess.Open();daTemplate.Fill(dsAccess, "templates");dtTemplate = dsAccess.Tables["templates"];PageHeader.Text = dtTemplate.Rows[0]["template_header"].ToString();PageFooter.Text = dtTemplate.Rows[0]["template_footer"].ToString();daLinks.Fill(dsAccess, "links");dtLinks = dsAccess.Tables["links"];dtLinksCount = dtLinks.Rows.Count;PageLinks.Text = "";int iLoop;for (iLoop=0; iLoop < dtLinksCount; iLoop++){PageLinks.Text = PageLinks.Text + "<a href=";PageLinks.Text = PageLinks.Text + dtLinks.Rows[iLoop]["link_url"];PageLinks.Text = PageLinks.Text + ">";PageLinks.Text = PageLinks.Text + dtLinks.Rows[iLoop]["link_text"];PageLinks.Text = PageLinks.Text + "</a>";if (iLoop < dtLinksCount-1){PageLinks.Text = PageLinks.Text + " | ";}}daCategory.Fill(dsAccess, "category");dtCategory = dsAccess.Tables["category"];dtCategoryCount = dtCategory.Rows.Count;PageCategory.Text = "";for (iLoop=0; iLoop < dtCategoryCount; iLoop++){PageCategory.Text = PageCategory.Text + "<a href=";PageCategory.Text = PageCategory.Text + dtCategory.Rows[iLoop]["category_url"];PageCategory.Text = PageCategory.Text + ">";PageCategory.Text = PageCategory.Text + dtCategory.Rows[iLoop]["category_text"];PageCategory.Text = PageCategory.Text + "</a><br>";}daPage.Fill(dsAccess, "pages");dtPage = dsAccess.Tables["pages"];PageContent.Text = "";PageContent.Text = PageContent.Text + "<center><b>" ;PageContent.Text = PageContent.Text + dtPage.Rows[0]["page_title"];PageContent.Text = PageContent.Text + "<br>";PageContent.Text = PageContent.Text + dtPage.Rows[0]["page_subtitle"];PageContent.Text = PageContent.Text + "</b><br></center>";PageContent.Text = PageContent.Text + dtPage.Rows[0]["page_text"];if (Request.QueryString["category"] != null){string ssCatPage = "Select page_id, page_title, page_subtitle From pages Where page_category = " + Request.QueryString["category"];SqlDataAdapter daCatPage = new SqlDataAdapter(ssCatPage, dcAccess);DataTable dtCatPage = new DataTable();int dtCatPageCount;daCatPage.Fill(dsAccess, "catpages");dtCatPage = dsAccess.Tables["catpages"];dtCatPageCount = dtCatPage.Rows.Count;for (iLoop=0; iLoop < dtCatPageCount; iLoop++){PageContent.Text = PageContent.Text + "<p>";PageContent.Text = PageContent.Text + "<a href=default.aspx?page=";PageContent.Text = PageContent.Text + dtCatPage.Rows[iLoop]["page_id"];PageContent.Text = PageContent.Text + ">";PageContent.Text = PageContent.Text + dtCatPage.Rows[iLoop]["page_title"];PageContent.Text = PageContent.Text + "</a><br>";PageContent.Text = PageContent.Text + dtCatPage.Rows[iLoop]["page_subtitle"];PageContent.Text = PageContent.Text + "</p>";}}}finally{dcAccess.Close();}} |
|
jhermiz
3564 Posts |
Posted - 2005-05-08 : 14:15:51
|
Couple of things,1) Dont use select *2) Do any of your other tables have that same field name???If so that's probably your error, your procedure can't tell fromwhich table you want this field. Try prefixing, dbo.tablename.field.Some of your code is not needed and you'll take a performance hit with the way you are doing things. Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
|
|
|
|
|