在对数据库执行查询、更新、修改的时候不可避免的要使用参数或者变量,,而此时如果我们使用string的Format方法将极大的减少代码和避免错误的发生。
string.Format方法是对一个字符串进行格式化,返回的也是字符串。如:
1。string str = string.Format("select * from 表 where username='{0}',txtName.Text");
2。string selStr = string.Format("select * from 表 where id={0}",整数);
3。string insertStr = string.Format("insert into 表(username,userpass) values('{0}','{1}')",txtName.Text,txtPass.Text);