解决方案 »

  1.   


    数据库基础 insert和update
      

  2.   

    不就是普通的插入更新操作吗,msdn上都有示例代码
      

  3.   

    参考实例:http://blog.163.com/qqabc20082006@126/blog/static/229285252009719104647132/
       int id = 0;
                //使用存储过程实现添加数据
                //proc_AddUser为存储过程名称
                using (SqlCommand command = new SqlCommand("proc_AddUser", DBService.Conn))
                {
                    //指定command对象的执行方式
                    command.CommandType = CommandType.StoredProcedure;
                    //指定存储过程的参数并赋值
                    command.Parameters.Add("@uName",SqlDbType.NVarChar,20).Value = user.Name; 
                    command.Parameters.Add("@uAge", SqlDbType.Int).Value = user.Age;
                    command.Parameters.Add("@uPass", SqlDbType.NVarChar, 200).Value = user.Password;
                    //设置输出参数
                    command.Parameters.Add("@uId", SqlDbType.Int).Direction                                            =ParameterDirection.Output;   //@uId,@uName等参数必须与数据库存储过程中的参数一致
      //执行
      command.ExecuteNonQuery();
      //获取输出参数的值
                    id = Convert.ToInt32(command.Parameters["@uId"].Value);f exists (select * from sysobjects where name = 'proc_AddUser')
    drop proc proc_AddUser
    go
    create procedure proc_AddUser
    @uId int output,
    @uName nvarchar(20),
    @uAge int,
    @uPass nvarchar(200)
    with encryption  --对存储过程进行加密
    as
    insert into UserInfo (uName,uAge,password) values (@uName,@uAge,@uPass)
    select @uId = @@identity
    go