zoukankan      html  css  js  c++  java
  • 完整删除

    删除

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlClient;
    
    namespace Delete1
    {
        class Program
        {
            static void Main(string[] args)
            {
                bool has = false;//默认has  false
                Console.Write("请输入要删除的编号:");
                string ucode = Console.ReadLine();
    
                //先查询有无此数据
                SqlConnection conn = new SqlConnection("server=.;database=Data0504;user=sa;pwd=123;");
                SqlCommand cmd = conn.CreateCommand();
    
                cmd.CommandText = "select *from Users where Ucode=@a";
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@a", ucode);
    
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)//如果查到数据让has=true
                {
                    has = true;
                }
                conn.Close();
    
                if (has)//如果has=true删除成功
                {
                    //执行删除
                    Console.WriteLine("删除成功!");
                }
                else
                {
                    Console.WriteLine("未查到此编号数据,请确定编号是否正确!");
                }
    
    
    
    
    
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    android作业10.21
    安卓10.7作业
    安卓9.30
    9.23作业
    9.17安卓作业
    6.12作业
    5.29作业
    5.28上机作业
    leetcode 219
    策略模式
  • 原文地址:https://www.cnblogs.com/skyhorseyk/p/7205878.html
Copyright © 2011-2022 走看看