zoukankan      html  css  js  c++  java
  • SQL相关增删改查语句

    Sql Server中

    1,增加数据:

    insert into MessageList (Name,Emails,Contents) values ('王海鹏','tcnf2008@hotmail.com','dd')

                    表名(列)   values (数据项);

      

    代码
    // 在数据表里创建一个新行,并把当前属性的值插入对应的列中
    public int Create()
    {
    //建立数据库连接
    SqlConnection connection = new SqlConnection(_Connectionstring);
    connection.open();
    //打开数据库连接
    //建立数据库连接对象
    SqlCommand command = new SqlCommand("insert into Customers "
    +"(LastName,FirstName,Address,City,State,Zip,Phone,"
    +"SignUpDate) values (@LastName,@FirstName,@Address,"
    +"@City,@Zip,@Phone,@SignUpDate)",connection);

    //将要插入的数据加入数据库中
    command.Parameters.AddWithValue("@LastName",_LastName);
    command.Parameters.AddWithValue(
    "@FirstName",_FirstName);
    command.Parameters.AddWithValue(
    "@Address",_Address);
    command.Parameters.AddWithValue(
    "@City",_City);
    command.Parameters.AddWithValue(
    "@Zip",_Zip);
    command.Parameters.AddWithValue(
    "@Phone",_Phone);
    command.Parameters.AddWithValue(
    "@SingUpDate",_SingUpDate);

    command.ExecuteNonQuery();
    //执行连接语句
    command.Parameters.Clear();
    command.CommandText
    = "select @@IDENTITY"; //查找主键
    int newCustomerID = Convert.ToInt32(command.ExecuteScalar());
    connection.Close();
    //关闭连接
    _CustomerID = newCustomerID;
    return newCustomerID;
    }

    2,删除数据:

    3,修改数据:

    4,查询语句:

      select * from user where ulname like '%ad%'

      SECLET * FROM 图书表 WHERE 作者 LIKE '%

    5,执行SQL语句:

    sqlcmd.connection.open();

    sqlcmd.ExecuteNonQuery();

  • 相关阅读:
    今天冷兔上线.
    tweenlite
    AS3中对String操作的replaceAll方法
    咫尺天涯的幸福
    ESPCMS系统模板结构图
    [转]AIR中调用exe或者bat可执行文件
    摘自《做人还是现实些》
    framespacing="10"和border="10"在frameSet中有什么区别?
    一个简单的div与span例子
    理解Javascript_05_原型继承原理 ,转载文章
  • 原文地址:https://www.cnblogs.com/netact/p/1773403.html
Copyright © 2011-2022 走看看