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

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();
posted @ 2006-03-29 09:42  New Yang Bo Element  阅读(650)  评论(0编辑  收藏  举报