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!");
            }
  • 相关阅读:
    Redis list数据结构
    Redis hash结构
    大公司都有哪些开源项目~~~阿里,百度,腾讯,360,新浪,网易,小米等
    使用Nexus搭建Maven私服
    Maven nexus 安装nexus私服出现的两个问题
    SONATYPE NEXUS 搭建MAVEN 私服
    http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html
    将 Smart 构件发布到 Maven 中央仓库
    http://www.ruanyifeng.com/blog/2013/07/gpg.html
    http://www.jianshu.com/p/1e402922ee32/
  • 原文地址:https://www.cnblogs.com/perfect/p/578605.html
Copyright © 2011-2022 走看看