locked
Announcements table : add new column but article never stored RRS feed

  • Question

  • User-585989643 posted

    I've created a new column in the announcement table to add a new paramater "category". Here's my code to do this stuff :

    1) Define a new column in Announcements (VARCHAR(50)) 

    2) Changed Page_load in  New_List.aspx.cs to pass category parameter in querystring on "Add new article" click :

    <asp:Panel ID="panel1" runat="server" CssClass="actionbuttons">

    <Club:RolloverLink ID="RemoveBtn" runat="server" Text="Add new Article" NavigateURL="News_Edit.aspx?Action=New&category=" />

    </asp:Panel>

     

    ... 

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!IsPostBack)

    RemoveBtn.NavigateURL += Request.QueryString["category"];

    IsAdmin = User.IsInRole("Administrators");

    panel1.Visible = IsAdmin;

    }

    3) Modified Sqldatasource to store the querystring parameter "category" in New_Edit.aspx file :

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"

    SelectCommand="SELECT id, itemdate, title, description, staticURL, photo, albumid from announcements where Announcements.id=@id"

    InsertCommand="INSERT INTO Announcements(itemdate, title, description, category, staticURL, photo, albumid) VALUES (@itemdate, @title, @description, @category, @staticURL, @photo, @albumid)"

    UpdateCommand="UPDATE Announcements SET itemdate = @itemdate, title = @title, description = @description, category = @category, staticURL = @staticURL, photo = @photo, albumid = @albumid WHERE (id = @id)"

    DeleteCommand="Delete from Announcements where id=@id" OldValuesParameterFormatString="{0}" >

    <SelectParameters>

    <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" />

    <asp:QueryStringParameter Name="category" QueryStringField="category" />

    </SelectParameters>

    <UpdateParameters>

    <asp:Parameter Name="itemdate" Type="DateTime" />

    <asp:Parameter Name="title" Type="String" />

    <asp:Parameter Name="description" Type="String" />

    <asp:Parameter Name="category" Type="String" />

    <asp:Parameter Name="staticURL" Type="String" />

    <asp:Parameter Name="location" Type="String" />

    <asp:Parameter Name="photo" Type="Int32" />

    <asp:Parameter Name="id" Type="Int32" />

    <asp:Parameter Name="albumid" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="itemdate" Type="DateTime" />

    <asp:Parameter Name="title" Type="String" />

    <asp:Parameter Name="description" Type="String" />

    <asp:Parameter Name="category" Type="String" />

    <asp:Parameter Name="staticURL" Type="String" />

    <asp:Parameter Name="location" Type="String" />

    <asp:Parameter Name="photo" Type="Int32" />

    <asp:Parameter Name="id" Type="Int32" />

    <asp:Parameter Name="albumid" Type="Int32" />

    </InsertParameters>

    <DeleteParameters>

    <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" />

    </DeleteParameters>

    </asp:SqlDataSource>

     But, when I run the website, the category value is never stored in the database.Angry

    The insert statement seems not to be executed, the article doesn't appears in the list.

    Thanks for your support.

    Sunday, November 25, 2007 1:50 PM

All replies

  • User2069888697 posted

    The datasource looks fine, what it looks like is the catagory value is not being passed properly.

    What should the catagory value be and where is the value coming from. Is it selecected from a dropdown or text box when the article is created?

    Monday, November 26, 2007 6:12 AM
  • User-585989643 posted

    The category value is coming from the following control. This control is inherited from asp:button

    <Club:RolloverLink ID="RemoveBtn" runat="server" Text="Add new Article" NavigateURL="News_Edit.aspx?Action=New&category=" />

    The category can be equal to string like "Seniors", "18years", "13years". For example, the navigateURL could be "News_Edit.aspx?Action=New&category=Seniors"

    I modified the Web.sitemap file to add sub menus in the "News" menu. The category parameter is initialised in relation with the sub-menu selection.

    Note that I tried to write directly the category value in the NavigateURL as above but the result was not good. The new article is never stored in the DB. I also verified that the URL parameter is well received in the destination page (News_Edit.aspx.cs, page_load : object o2 = Request.QueryString["Category"];), all is ok.

    Thanks to give me some advices to debug this issue. I would really appreciate to go ahead with the club starter kit.

    Tuesday, November 27, 2007 3:58 AM
  • User2069888697 posted

    I think you may fin the Rolloverlink may be causing the issue. I would troubleshoot it by.

    1. add a Text onto the news_edit page and on page load event put textbox1.text=Category ( this will let you know if the value is making it to the page)

    2. If it is getting to the page, the problem may be that the clubrollover button is a call to a seperate sub routine, you may be losing the value between the sub routine and whan the sql command is attempted.

    3. If that is the case one way to fix it coulod be to leave the Textbox on the page use it to get the data to the sql.(you will have to put the textbox1.text=Category into an If Not IsPostBack Then to prevent any change on the Rollover buttons postback.

     

    Tuesday, November 27, 2007 5:17 AM
  • User-585989643 posted

    I added a label control into the News_Edit.aspx.cs page and on page_load event put "Label2.Text = Request.QueryString["category"];". The category value is written correctly. But I can't insert an article in the database. 

     I also modified the SqlDataSource as listed below : I moved the  QueryStringParameter control from SelectCommand to InsertCommand. But the insert was not ok. I can't understand why a simple insert with SqlDataSource doesn't work.

     Any help would be appreciated.

    Thanks for you support.

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"

    SelectCommand="SELECT id, itemdate, title, description, staticURL, photo, albumid from announcements where Announcements.id=@id"

    InsertCommand="INSERT INTO Announcements(itemdate, title, description, category, staticURL, photo, albumid) VALUES (@itemdate, @title, @description, @category, @staticURL, @photo, @albumid)"

    UpdateCommand="UPDATE Announcements SET itemdate = @itemdate, title = @title, description = @description, category = @category, staticURL = @staticURL, photo = @photo, albumid = @albumid WHERE (id = @id)"

    DeleteCommand="Delete from Announcements where id=@id" OldValuesParameterFormatString="{0}" >

    <SelectParameters>

    <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" />

    </SelectParameters>

    <UpdateParameters>

    <asp:Parameter Name="itemdate" Type="DateTime" />

    <asp:Parameter Name="title" Type="String" />

    <asp:Parameter Name="description" Type="String" />

    <asp:QueryStringParameter Name="category" QueryStringField="category" Type="String" />

    <asp:Parameter Name="staticURL" Type="String" />

    <asp:Parameter Name="location" Type="String" />

    <asp:Parameter Name="photo" Type="Int32" />

    <asp:Parameter Name="id" Type="Int32" />

    <asp:Parameter Name="albumid" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="itemdate" Type="DateTime" />

    <asp:Parameter Name="title" Type="String" />

    <asp:Parameter Name="description" Type="String" />

    <asp:QueryStringParameter Name="category" QueryStringField="category" Type="String" />

    <asp:Parameter Name="staticURL" Type="String" />

    <asp:Parameter Name="location" Type="String" />

    <asp:Parameter Name="photo" Type="Int32" />

    <asp:Parameter Name="id" Type="Int32" />

    <asp:Parameter Name="albumid" Type="Int32" />

    </InsertParameters>

    <DeleteParameters>

    <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" />

    </DeleteParameters>

    </asp:SqlDataSource>

    Wednesday, November 28, 2007 4:03 PM
  • User-585989643 posted

    Could someone help me ?

    Is there a way to debug the sqlDataSource ? I want to verify if an error message is generated during the insert statement.

    Thanks for your support.

    Monday, December 3, 2007 6:07 AM