Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Help with stored proc and gridview (no replies)

$
0
0
I'm new to MySQL, and this is about to cause me to lose my mind. I tried this in SQL and everything worked perfectly. Unfortunately, my attempts to get it working in MySQL are stalling. What I'm trying to do is select a value from a dropdownlist and then populate a gridview with the data that corresponds to the relevant ID. Here's that part of the code:

    <b>Choose a rating:</b>

    <asp:DropDownList ID="ddlRatings" DataSourceID="objGetRatings" AutoPostBack="true" DataTextField="rating" DataValueField="ratingID" runat="server" />
    <asp:ObjectDataSource ID="objGetRatings" runat="server" TypeName="TheMovieMark.DAL.DBRatings" SelectMethod="GetRatings" />
    <br /><br />

    <asp:GridView ID="gvRatings" AllowSorting="True" AllowPaging="True" runat="server" DataSourceID="objCurrRating" 
        DataKeyNames="ratingID" AutoGenerateColumns="False" CssSelectorClass="TMMGridView" SelectedIndex="0" 
        OnSelectedIndexChanged="gvRatings_SelectedIndexChanged" OnPageIndexChanged="gvRatings_PageIndexChanged" 
        OnRowDeleted="gvRatings_RowDeleted" OnSorted="gvRatings_Sorted">
        <Columns>
            <asp:BoundField DataField="ratingID" HeaderText="ID" ReadOnly="True" SortExpression="ratingID" />
            <asp:BoundField DataField="rating" HeaderText="Rating" SortExpression="rating" />
            <asp:CommandField ButtonType="Image" SelectImageUrl="~/App_Themes/TMM/images/Edit.gif" SelectText="Update Category"
                ShowSelectButton="true">
                <ItemStyle HorizontalAlign="Center" />
            </asp:CommandField>
            <asp:CommandField ButtonType="Image" DeleteImageUrl="~/App_Themes/TMM/images/Delete.gif" SelectText="Delete Category"
                ShowDeleteButton="true">
                <ItemStyle HorizontalAlign="Center" />
            </asp:CommandField>
        </Columns>
    </asp:GridView>
    
    <asp:ObjectDataSource ID="objCurrRating" runat="server" TypeName="TheMovieMark.DAL.DBRatings" SelectMethod="GetRatingByID" 
        DeleteMethod="DeleteRating">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlRatings" Name="ratingID" PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>    
    </asp:ObjectDataSource>

    <br />

Here's my stored proc:

CREATE PROCEDURE GetRatingByID
(
   IN RatingID INT
)
BEGIN
   SELECT * 
   FROM tmm_Ratings
   WHERE ratingID = RatingID;
END;

And here's the stored proc call (this code is stored in a separate class):

public DataSet GetRatingByID(int ratingID)
{
     MySqlConnection conn = new MySqlConnection(connectionString);
     MySqlCommand cmd = new MySqlCommand("GetRatingByID", conn);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("?RatingID", MySqlDbType.Int32).Value = ratingID;

     return FillMySQLDataSet(cmd, "CurrRating");
}

The problem is when I choose a value from the dropdownlist, it populates the gridview with all the data in the table rather than the item that corresponds to the ratingID. This is an even bigger problem when I try to run my update/delete stored procs because it updates/deletes EVERY item in the table. It's almost as if it's ignoring the WHERE clause.

Like I said, the SQL equivalent worked perfectly. Is there something wrong with my syntax? Any thoughts. Your help in getting past this issue will be much appreciated.

Thanks!

Adam

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>