2020-12-07

窗体

实现增删查功能
一,主页面

在这里插入图片描述

二,查询窗口

在这里插入图片描述

代码连接

SqlConnection conn =new SqlConnection(“Data Source=.;Initial Catalog=dbok;User ID=sa;Password=cnm.040513”);

        string sql = "select * from QQcard where qqname = "+textBox1.Text;
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataReader result = cmd.ExecuteReader();
       while(result.Read())
        {
           
            
            string tempName = result["qqname"].ToString();//查询姓名
            string tempAge = result["qqnameber"].ToString();//qq号
          
            ListViewItem item = new ListViewItem(tempName);
            listView1.Items.Add(item);
            item.SubItems.Add(tempAge);
            
            
        }
       conn.Close();

搜索功能代码展示

listView1.Items.Clear();
string ww = “”;
int ww1 = 0;
try { ww1 = Convert.ToInt32(textBox1.Text); }
catch { ww = textBox1.Text; }
String sql2 = “select * from QQcard where nickname = '”+ww+"’ or qqid= “+ww1+”;";
conn.Open();
SqlCommand cmd = new SqlCommand(sql2, conn);
try
{
SqlDataReader result = cmd.ExecuteReader();
result.Read();
string tempName = result[“qqname”].ToString();//查询姓名
string tempAge = result[“qqnameder”].ToString();//qq号

            ListViewItem item = new ListViewItem(tempName);
            listView1.Items.Add(item);
            item.SubItems.Add(tempAge);
           
            conn.Close();
        }
        catch {
            conn.Close();
            MessageBox.Show("请输入内容!");
        }

右键删除功能代码展示

MessageBox.Show(listView1.SelectedItems[0].SubItems[1].Text);

        String sql = String.Format("delete from QQcard where qqnameber  = {0}", listView1.SelectedItems[0].SubItems[1].Text);

        MessageBox.Show(sql);
        //开启对象
        conn.Open();

        SqlCommand cmd = new SqlCommand(sql, conn);

        
        int n = cmd.ExecuteNonQuery();

        MessageBox.Show("受影响的行为"+n);

        //关一下
        conn.Close();

        //清空listview对象中的项
        listView1.Items.Clear();

        //重新加载load一下load
        loadData();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值