注册 登录
编程论坛 C# 论坛

listView1 与contextMenuStrip1的用法

dingchentao 发布于 2016-03-10 23:50, 2193 次点击
我要用contextMenuStrip1删除listView1 里面选中的数据包括删除数据库中的数据

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(cstr);
            conn.Open();
            int id = Convert.ToInt32(listView1.);//此处代码请教大神怎么打
            string sql = string.Format("delete from Student where StudentId='{0}'",id);
            SqlCommand cmd = new SqlCommand(sql,conn);
           
            int a = cmd.ExecuteNonQuery();
            if (a > 0)
            {
                MessageBox.Show("删除成功");
            }
            else if (a==0){
                MessageBox.Show("删除失败");
            }
        }
1 回复
#2
qq10235692232016-03-11 08:51
https://msdn.
1