0
private void button6_Click(object sender, EventArgs e)
{
    xcon.Open();
    SqlDataAdapter xadapter = new SqlDataAdapter();
    SqlCommand command = new SqlCommand(
    "UPDATE dbo.SysX SET fp = @fp, sd = @sd, sf= @sf" +
    "WHERE id = 2019", xcon);
    command.Parameters.Add("@fp", SqlDbType.Int, 5, textBox1.Text);
    command.Parameters.Add("@sd", SqlDbType.Int, 40, textBox2.Text);
    command.Parameters.Add("@sf", SqlDbType.Int, 40, textBox3.Text);
    xadapter.UpdateCommand = command;
    xcon.Close();
}

looking to update information inside data base where id = 2019 on click of button. Nothings happens and do not get error... i am not using data table just updating

what am i doing wrong?

1 Answers1

1

1) You missed Execute the query 2) Convert to the correct type 3) In addition, I'd put ID as a parameter too.

private void button6_Click(object sender, EventArgs e)
{
    xcon.Open();
    SqlDataAdapter xadapter = new SqlDataAdapter();
    SqlCommand command = new SqlCommand(
    @"UPDATE dbo.SysX SET fp = @fp, sd = @sd, sf= @sf
    WHERE id = @id", xcon);
    command.Parameters.Add("@fp", SqlDbType.Int, Convert.ToInt32(textBox1.Text));
    command.Parameters.Add("@sd", SqlDbType.Int, Convert.ToInt32(textBox2.Text));
    command.Parameters.Add("@sf", SqlDbType.Int, Convert.ToInt32(textBox3.Text));
    command.Parameters.Add("@Id", SqlDbType.Int, 2019);
    // next command !!!
    command.ExecuteNonQuery();
    xadapter.UpdateCommand = command;
    xcon.Close();
}
tgralex
  • 794
  • 4
  • 14