heiziling 2021-12-07 10:40 采纳率: 83.3%
浏览 22

C#运行发生错误,该怎么改?

img

会发生错误

img

以下就是代码了:

        //判断是否选中行
        if(dataGridView1.SelectedRows.Count>0)
        {

        }
        else
        {
            MessageBox.Show("请选择要删除的行");
            return;
         }
        //获取输入的信息
        string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
        
        //删除操作
        string strsql = "selete from kqlog where id='" + id + "'";
        // 添加异常处理
        try
        {
            SqlConnection con = GetCon();
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandText = strsql;
            int count = cmd.ExecuteNonQuery();
            if (count > 0)
            {
                this.toolStripStatusLabel1.Text = "操作成功 !";
            }
            con.Close();
            shuxin();
        }
        catch (Exception ex)
        {

            this.toolStripStatusLabel1.Text = "操作失败!失败原因:" + ex.Message;

        }
  • 写回答

2条回答 默认 最新

  • 南城Flipped 2021-12-07 10:43
    关注

    img


    select语句没有列要求 *号也得有吧

    评论

报告相同问题?

问题事件

  • 创建了问题 12月7日