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!");
            }
  • 相关阅读:
    Win7+IIS伪静态 UrlRewriter配置
    让VS2010打包工具找回丢失的.net 2.0 .
    高效注册DLL控件 让你的IE浏览器复活
    查询及删除重复记录的方法
    .NET代码模板生成工具CodeSmith 5.0.1 专业版完美版下载
    如何使用CslaGen生成CSLA DAL层代码
    用C# + WebBrowser控件抓取AJAX页面的内容[转]
    了解IIS6应用程序池假死问题解决办法
    美化界面2
    C# WebBrowser高级应用
  • 原文地址:https://www.cnblogs.com/perfect/p/578605.html
Copyright © 2011-2022 走看看