执行Insert语句时使用string的Format用法
2006-12-01 09:57
609 查看
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!");
}
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!");
}
相关文章推荐
- 执行Insert语句时使用string的Format用法
- SQL Server 的动态语句(SQLServer 的String.format用法)(SQLServer的调用SQL占位符的使用)
- SQLCMD的用法,使用CMD 执行sql语句
- oracle中merge into..using..on..when..when..用法 使用一条语句实现update/insert 语句
- C#使用oledb连接excel执行Insert Into语句出现“操作必须使用一个可更新的查询”的解决办法
- SQLCMD的用法,使用CMD 执行sql语句
- 关于加快INSERT语句执行速度和HINT /*+ append */及/*+ append nologging */的使用
- hibernate4中使用createSQLQuery方法执行sql语句的用法
- String高级用法---format使用详解
- 连接excel执行Insert Into语句出现“操作必须使用一个可更新的查询”的解决
- 关于加快INSERT语句执行速度和 HINT /*+ append*/及nologging的使用
- PLSQL语句执行正确,而VB执行错误。ORA-01830 date format picture ends before converting entire input string
- String android.content.Context.getString(int resId, Object... formatArgs)的使用
- String.Format用法
- delphi中VirtualStringTree树使用方法之终结篇!2011-07-01 14:06VirtualStringTree 的用法详解:
- 关于jstl EL用法的注意点(java.lang.NumberFormatException: For input string: "userName")
- Yii 直接执行SQL语句的几种使用方法
- DB2数据迁移到mysql,使用insert语句
- JAVA字符串格式化-String.format()的使用
- DataFormatString="{0:格式字符串}" 用法