zoukankan      html  css  js  c++  java
  • ADO.NET教程(四)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;//必须引入
    using System.Data.SqlClient;//必须引入
    
    namespace Command
    {
        class Program
        {
            static void Main(string[] args)
            {
                string connSQL = @"Data Source=.SQLEXPRESS; Initial Catalog=db_MyDemo; Integrated Security=SSPI";//构造连接字符串
                SqlConnectionStringBuilder connStr = new SqlConnectionStringBuilder(connSQL);
    
                using(SqlConnection conn = new SqlConnection(connStr.ConnectionString))
                {
                    //拼接SQL语句
                      StringBuilder strSQL = new StringBuilder();
                    strSQL.Append("insert into tb_SelCustomer ");
                    strSQL.Append("values(");
                    strSQL.Append("'liuhao','0','0','13822223333','liuhaorain@163.com','广东省深圳市宝安区',12.234556,34.222234,'422900','备注信息')");
    
                    Console.WriteLine("Output SQL:
    {0}",strSQL.ToString());
    
                    //创建Command对象
                      SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = strSQL.ToString();
    
                    try
                    {
                        conn.Open();//一定要注意打开连接
    
                           int rows = cmd.ExecuteNonQuery();//执行命令
                           Console.WriteLine("
    Result: {0}行受影响",rows);
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine("
    Error:
    {0}", ex.Message);
                    }
                }
    
                Console.Read();
            }
        }
    }
  • 相关阅读:
    网络爬虫基础练习
    综合练习:词频统计
    Hadoop综合大作业
    理解MapReduce
    熟悉常用的HBase操作
    第三章、熟悉常用的HDFS操作
    爬虫大作业
    数据结构化与保存
    使用正则表达式,取得点击次数,函数抽离
    爬取校园新闻首页的新闻
  • 原文地址:https://www.cnblogs.com/aipohoo/p/5428178.html
Copyright © 2011-2022 走看看