Click here to Skip to main content
15,909,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying get value from gridview and decrement it and it work, but insert it to database can't work. What's wrong?

C#
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
    m = GridView1.SelectedRow.Cells[5].Text;
    int nm = Convert.ToInt32(m);
    if (GridView1.SelectedRow.Cells[5].Text != "")
    {
        cn.Open();
        nm--;
        cmd.CommandText = ("INSERT INTO rezerwacje [miejsca] VALUES(@nm)");
        //cmd.ExecuteNonQuery();
        cmd.Clone();
        cn.Close();
    }

}
Posted
Comments
[no name] 23-Apr-14 13:55pm    
Mostly because you are not creating the parameters for your command and never executing your command. Why you are creating a clone of your command is a mystery.

1 solution

You need to add the parameter for @nm e.g.
cmd.Parameters.Add("@nm", SqlDbType.SmallInt).Value = nm;

Secondly uncomment the line
C#
cmd.ExecuteNonQuery();

Thirdly get rid of
cmd.Clone();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900