数据库插入使用参数的方法 一般步骤

1、通过命令插入数据

SqlCommand sqlcmd=new SqlComand("insert into table ("iditem","nameitem","sexitem")values(@id,@name,@sex)",con)

2、创建参数

sqlcom.Paramaters.Add(new SqlParamater("@id",SqlDbType.Varchar,10));  即将插入数据库中id 的属性,必须和数据库iditem 的属性一致;

3、设置参数值

sqlcom.Paramaters("id").value="yangbo"

4、执行

sqlcom.ExecuteNonQuery();
原文地址:https://www.cnblogs.com/gergro/p/361489.html