954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

GridView updating database

Hello guyz,

First of all, sorry for starting new thread with similar topic but I read each and still can't figure out how to do it.

I'm having a database, using GridView I retrieve the data into my WEB application.
Then I set the rows to editable (not sure if it is fully completed) and when I edit some cells I want to update the GridView AND the database behind.
When I click on 'edit' then the button is changed to update - great but I get some unhandled exception. I don't expect anything else to happen since I didn't put any code in the update methods like RowCommand, RowUpdating, RowUpdated, RowDataBound. I'm really confused what goes there and what exactly do I need.

I'm using C# with Microsoft Visual Studio and MySQL database.

Please help if you can
Would be grateful.

Thanks

pepyrs
Light Poster
25 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Can you post your GridView Control Structure and the code you are using to bind the Grid?

jbisono
Posting Pro in Training
442 posts since May 2009
Reputation Points: 71
Solved Threads: 59
 

Hey,
I jsut got it working today. It suddenly updated the gridview AND the database without giving me some exceptions and syntax errors as before.
But here it is anyway :)

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Table view</h2>
    <p>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:dbcssConnectionString %>" 
            
            ProviderName="<%$ ConnectionStrings:dbcssConnectionString.ProviderName %>" 
            SelectCommand="SELECT * FROM tableview" 
            UpdateCommand="UPDATE tableview SET Pad_No = @pad_no, Lift1 = @lift1, Lift2 = @lift2, Lift3 = @lift3, Task4 = @task4, Task5 = @task5, Task6 = @task6, Task7 = @task7, Task8 = @task8 WHERE row_No = @row_no">
          
            <UpdateParameters>
                <asp:Parameter Name="Pad_No" Type="String" />
                <asp:Parameter Name="Lift1" Type="Int32" />
                <asp:Parameter Name="Lift2" Type="Int32" />
                <asp:Parameter Name="Lift3" Type="Int32" />
                <asp:Parameter Name="Task4" Type="Int32" />
                <asp:Parameter Name="Task5" Type="Int32" />
                <asp:Parameter Name="Task6" Type="Int32" />
                <asp:Parameter Name="Task7" Type="Int32" />
                <asp:Parameter Name="Task8" Type="Int32" />
                <asp:Parameter Name="row_No" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </p>
        </asp:Content>


And then I have on line of code in the Default.aspx.cs file:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               //not working without that one ?
            }
        }

No methods like RowUpdating, RowUpdated, RowEditing etc, etc.
Isn't that strange though ?

pepyrs
Light Poster
25 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Very good!!!!, and yes when using SqlDataSource procedure such as update, select, delete, sort and paging is really easy to do, but you have less control over the GridView.

jbisono
Posting Pro in Training
442 posts since May 2009
Reputation Points: 71
Solved Threads: 59
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: