zoukankan      html  css  js  c++  java
  • 执行Insert语句时使用string的Format用法

           SqlConnection conn = new SqlConnection("server=zzy;integrated security=sspi;database=library");
            SqlCommand cmd;
            
    private void btninsert_Click(object sender, EventArgs e)
            {
                conn.Open();
                
    string _sql = "insert into login values('{0}','{1}','{2}')";

                
    /*  
                      Format方法:
                      ①、string.Format(string format,object arg0);
                      ②、string.Format(string format,params object[] args);
                      ③、string.Format(IFormatProvider provider,string format,params object[] args);
                      ④、string.Format(string format,object arg0,object arg1,object arg2);
                
    */

                
    //④:string.Format(string format,object arg0,object arg1,object arg2);
                _sql = string.Format(_sql, this.textBox1.Text.ToString().Trim(),this.textBox2.Text.ToString().Trim(),this.textBox3.Text.ToString().Trim());

                
    /*
                      ②:string.Format(string format,params object[] args); 
                      object[] aa = new object[] { 'a', 'b', 'c', 'd', 'e' }; 
                      _sql = String.Format(_sql, aa);
                
    */
                cmd 
    = new SqlCommand(_sql, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                MessageBox.Show(
    "Insert the values Successfully!");
            }
  • 相关阅读:
    关于网购心态
    c++ In STL maps, is it better to use map::insert than []? Stack Overflow
    小工具:sshcopyid_老王的技术手册 ( 我的新博客:http://huoding.com )_百度空间
    djangoqbe
    C++ STL map的使用
    容器find_if函数定义和其第三个参数重载的疑问
    ArchLinux的安装与配置
    使用Grub进行Linux的硬盘安装与修复
    MySQL数据类型简介
    ArchLinux下Alsa的简单配置
  • 原文地址:https://www.cnblogs.com/perfect/p/578605.html
Copyright © 2011-2022 走看看