QQフォームの割り当て

QQフォーム

ここに画像の説明を挿入します
ここに画像の説明を挿入します

コード表示

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();
String sql = String.Format("insert into QQCard(qqname,qqnumber) values('五一',22)");
            MessageBox.Show(sql);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql,conn);
            SqlDataReader reader = cmd.ExecuteReader();
            conn.Close();
            lvCards.Items.Clear();
            loadData();

おすすめ

転載: blog.csdn.net/qq_50722361/article/details/110790750