1
private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
    if (listView1.SelectedItems.Count > 0)
    {
        DataRowView drv = (DataRowView)listView1.SelectedItem;
        string id = drv.Row[0].ToString();
        string Saxeli = textBox4.Text;
        string misamarti = textBox2.Text;

        SqlConnection con = new SqlConnection("Data Source=DESKTOP-PR8PO9S;Initial Catalog=tel_operator;Integrated Security=True");
        con.Open();
        SqlCommand comm = new SqlCommand("update abonenti set gvari = @gvari where id =@id", con);

        comm.Parameters.AddWithValue("@gvari", textBox1.Text);
        comm.Parameters.AddWithValue("@saxeli", textBox4.Text);
        comm.Parameters.AddWithValue("@misamarti", textBox2.Text);
        comm.Parameters.AddWithValue("@id", textBox3.Text);

        comm.ExecuteNonQuery();
        con.Close();
        ShowData();
    }
}

WPF C# .NET

当我单击所选数据时帮助我,文本块中未打印的值和更新不起作用。如果我删除“if”条件并手动写入 ID,将执行更新。我无法通过单击更新来选择数据。谢谢

4

0 回答 0