Insert into MySql using GridView imagebutton from labels C#

I want to fetch the data from labels in Gridview and insert them to MySql database. When users click the imagebutton, the data will be inserted to MySql DB. I can't seem to make it happen with these codes:

//The Backend
   private void Insert(string bookTitle, string name, string date, string memberID, string phone)
                string q4 = "insert into c_records (bookTitle, date, name, memberID, phone) values (@bookTitle, @date, @name, @memberID, @phone);";
                string q5 = "delete customers from customers where name = @name and memberID = @memberID;";
                MySqlCommand cmd = new MySqlCommand(q4 + q5, conn);
                cmd.Parameters.AddWithValue("@date", date);
                cmd.Parameters.AddWithValue("@memberID", memberID);
                cmd.Parameters.AddWithValue("@phone", phone);
                cmd.Parameters.AddWithValue("@book", bookTitle);
                cmd.Parameters.AddWithValue("@name", name);
                cmd.Parameters["@book"].Value = bookTitle;
                cmd.Parameters["@date"].Value = date;
                cmd.Parameters["@name"].Value = name;
                cmd.Parameters["@memberID"].Value = memberID;
                cmd.Parameters["@phone"].Value = phone;
                MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
            catch (Exception ex)

        protected void GridView1_InsDel(object sender, GridViewCommandEventArgs e)
            // If multiple buttons are used in a GridView control, use the
            // CommandName property to determine which button was clicked.
            if (e.CommandName == "Insert")
                // Convert the row index stored in the CommandArgument
                // property to an Integer.
                //   int index = Convert.ToInt32(e.CommandArgument);

                // Retrieve the row that contains the button clicked 
                // by the user from the Rows collection.      
                //GridViewRow row = GridView1.Rows[index];
                int i;
                for (i = 0; i < GridView1.Rows.Count; i++)
                    string bookTitle = GridView1.Rows[i].Cells[0].ToString();
                    string date = GridView1.Rows[i].Cells[1].ToString();
                    string name = GridView1.Rows[i].Cells[2].ToString();
                    string memberID = GridView1.Rows[i].Cells[3].ToString();
                    string phone = GridView1.Rows[i].Cells[4].ToString();

                    MySqlCommand cmd = new MySqlCommand("INSERT INTO c_records (bookTitle, date, name, memberID, phone) VALUES (@bookTitle, @date, @name, @memberID, @phone)", conn);
                    MySqlParameter book = new MySqlParameter("@bookTitle", bookTitle);
                    MySqlParameter dt = new MySqlParameter("@date", date);
                    MySqlParameter n = new MySqlParameter("@name", name);
                    MySqlParameter mb = new MySqlParameter("@memberID", memberID);
                    MySqlParameter p = new MySqlParameter("@phone", phone);



                    Insert(bookTitle, date, memberID, phone, name);
                    GridView1.EditIndex = -1;



Open in new window

//The Front End
 <asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" AutoGenerateColumns="False"  Width="721px" showfooter="true" OnRowUpdating="GridView1_RowUpdating" Height="411px" OnRowCommand="GridView1_InsDel">
                <asp:TemplateField HeaderText="Id">
                        <asp:Label ID="Label5" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                <asp:TemplateField HeaderText="Book Title">
                        <asp:Label ID="book" runat="server" Text='<%# Eval("bookTitle") %>'></asp:Label>
                <asp:TemplateField HeaderText="Date">
                        <asp:Label ID="date" runat="server" Text='<%# Eval("date") %>'></asp:Label>
                <asp:TemplateField HeaderText="Name">
                        <asp:Label ID="name" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                <asp:TemplateField HeaderText="Member ID">
                        <asp:Label ID="memberID" runat="server" Text='<%# Eval("memberID") %>'></asp:Label>
                <asp:TemplateField HeaderText="Phone">
                        <asp:Label ID="phone" runat="server" Text='<%# Eval("phone") %>'></asp:Label>
                <asp:TemplateField HeaderText="Sign Out">
                        <asp:ImageButton OnClientClick="return abc(this);" ID="signOut" CommandName="Insert" AlternateText="Available" ImageUrl="~/Images/unclick.png" runat="server" />

                        <asp:LinkButton ID="submit" runat="server" Text="Submit" CommandName="Update"><img src="Images/save.jpg" /></asp:LinkButton>


Open in new window

Please don't hesitate to tell me if there are any other solution.
K AkemiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You don't need dataadapter for insert and delete.

You can use executenonquery method on command object.


If you want to use dataadapter check below links. Examples are for sqlcommand but it should be same for mysql as well.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
K AkemiAuthor Commented:
Thank you for the solution. I just noticed about the executenonquery part.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.