在c#代码中实现一个sp InsertUpdate_delete [英] Implement One sp InsertUpdate_delete in c# code

查看:70
本文介绍了在c#代码中实现一个sp InsertUpdate_delete的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Hem Raj Thakur

如何在ac#代码中实现这个存储过程?

 创建  PROCEDURE  MasterInsertUpdateDelete 


@ id INTEGER,
@ first_name VARCHAR 10 ),
@ last_name VARCHAR 10 ),
@ salary DECIMAL 10 2 ),
@ city VARCHAR 20 ),
@ StatementType nvarchar ( 20 )= ' '

AS
BEGIN
IF @ StatementType = ' 插入'
BEGIN
insert into employee(id,first_name,last_name,salary,city) values @id @ first_name @ last_name @salary @ city
END
< span class =code-keyword> IF
@ StatementType = ' 选择'
BEGIN
选择 * 来自员工
END
IF @ StatementType = ' 更新'
BEGIN
更新员工 SET
First_name = @ first_name ,last_name = @last_name ,salary = @ salary
city = @ city
WHERE id = @ id
END
else IF @ StatementType = ' 删除'
BEGIN
DELETE < span class =code-keyword> FROM employee WHERE id = @ id
END
end



提前谢谢。

解决方案

这是一种执行此操作的方法的框架。填写空白并查看它的位置。

  private   enum  StatementType 
{
Insert,
Update,
删除
}
私有 void MasterInsertUpdateDelete( int id, string 首先, string last, double salary, string city,StatementType statementType)
{
switch (statementType)
{
case StatementType.Insert:
// 基于此构建查询声明类型
// 为了爱上帝使用paramatarize d查询
break ;

case StatementType.Update:
// 基于此语句类型构建查询
// For上帝的爱使用paramatarized查询
break ;

case StatementType.Delete:
// 基于此语句类型构建查询
// For上帝的爱使用paramatarized查询
break ;
}

// 构建连接对象< a href =http ://support.microsoft.com/kb/308611>如何执行此操作< / a>
// 执行它。
}


hi this is Hem Raj Thakur
How to implement this store procedure in a c# code?

Create PROCEDURE MasterInsertUpdateDelete
 
( 
    @id         INTEGER,
     @first_name  VARCHAR(10),
     @last_name   VARCHAR(10),
     @salary      DECIMAL(10,2),
     @city        VARCHAR(20), 
 @StatementType nvarchar(20) = '' 
) 
AS 
BEGIN 
IF @StatementType = 'Insert'
BEGIN
insert into employee (id,first_name,last_name,salary,city) values( @id, @first_name,  @last_name,  @salary, @city)   
END
IF @StatementType = 'Select'
BEGIN
select * from employee
END 
IF @StatementType = 'Update'
BEGIN
UPDATE employee SET
            First_name =  @first_name, last_name = @last_name, salary = @salary,
            city = @city
      WHERE id = @id
 END
 else IF @StatementType = 'Delete'
 BEGIN
 DELETE FROM employee WHERE id = @id
 END
 end


Thanks in advance.

解决方案

Here is a skeleton of one way to do this. Fill in the blanks and see where it gets you.

private enum StatementType
{
   Insert,
   Update,
   Delete
}
private void MasterInsertUpdateDelete( int id, string first, string last, double salary, string city, StatementType statementType )
{
   switch( statementType )
   {
      case StatementType.Insert:
         // Build a query based on this statement type
         // For the love of god use paramatarized queries
         break;

      case StatementType.Update:
         // Build a query based on this statement type
         // For the love of god use paramatarized queries
         break;

      case StatementType.Delete:
         // Build a query based on this statement type
         // For the love of god use paramatarized queries
         break;
   }

   // Build a connection object <a href="http://support.microsoft.com/kb/308611">How to do this</a>   
   // Execute it.
}


这篇关于在c#代码中实现一个sp InsertUpdate_delete的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆