惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
T
Threatpost
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
S
Securelist
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
S
Secure Thoughts
MyScale Blog
MyScale Blog
O
OpenAI News
P
Palo Alto Networks Blog
美团技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
TaoSecurity Blog
TaoSecurity Blog
量子位
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
Know Your Adversary
Know Your Adversary
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
宝玉的分享
宝玉的分享
PCI Perspectives
PCI Perspectives
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
I
InfoQ
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
S
Security @ Cisco Blogs
S
Schneier on Security
B
Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Cloudflare Blog
AWS News Blog
AWS News Blog
IT之家
IT之家
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
H
Heimdal Security Blog
I
Intezer
A
Arctic Wolf
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
W
WeLiveSecurity

博客园 - DingJun

Javascript 继承方法3 Javascript 继承方法2 Javascript 继承方法1 Call web service from excel Cannot load type (加载页面出错) 几个主流的浏览器引擎及判定 防止数据库日志文件增长 配置发布数据库服务器时碰到错误18483 一些有关。NET界面处理与多线程的文章 不可恢复的生成错误 在.Net安装项目中如何判断操作系统的版本 修改dataConfiguration.config文件 SQL Server 使用外部连接 在.NET下利用目录服务操纵本机用户和用户组 System.windows.forms.datagrid控件使用技巧 读取配置文件中的自定义节 区域设置与格式化(1) 默认的 IIS MIME 类型关联 在.NET中使用XPath查找指定元素时遇到的麻烦(以dataConfiguration.config为例)
使用Data access block
DingJun · 2005-07-17 · via 博客园 - DingJun

一、配置Data block所需参数
1,应用程序的配置文件(*.exe.config或者*.dll.config或者Web.config)

2,配置数据库连接串(dataConfiguration.config)

二、执行Sql语句

三、调用存储过程
1、插入新记录并从存储过程获取返回值
存储过程:

调用代码:

private void button4_Click(object sender, System.EventArgs e)
        
{
            
//@RETURN_VALUE,RETURN_VALUE,
            Database db = DatabaseFactory.CreateDatabase();
            DBCommandWrapper cmd 
= db.GetStoredProcCommandWrapper("usp_AddGroup");
            cmd.AddInParameter(
"@StaffID",DbType.String,"3290F849-031F-49B5-8CEE-0F98AA789731");
            cmd.AddInParameter(
"@GroupName",DbType.String,"yyyooo");
            cmd.AddInParameter(
"@Count",DbType.Int32,10);
            cmd.AddParameter(
"RetVal7",DbType.Int32,ParameterDirection.ReturnValue,"",DataRowVersion.Current,null);
            db.ExecuteNonQuery(cmd);
            
int a = (int)cmd.GetParameterValue("RetVal7");
            MessageBox.Show(a.ToString());
        }

2、返回记录集并获取存储过程返回值
存储过程:

调用代码:

3、返回记录集并通过输出参数获取返回值
存储过程:

调用代码:

4、DataRearder与输出参数
存储过程:

调用代码:

5、DataRearder与返回值
存储过程:

调用代码:

四、事务处理:

public static bool OpretRapportFraskabelon (string CVR, int maanedValoer)
        
{
            
try
            
{
                db 
= DatabaseFactory.CreateDatabase();
            }

            
catch(Exception ex)
            
{
                
throw new PensamDBException("Fejl i opret databasen",ex); 
            }

            
using (IDbConnection connection = db.GetConnection())
            
{
                connection.Open();
                IDbTransaction transaction 
= connection.BeginTransaction();
                
try
                
{
                    
int year = maanedValoer / 12 + 1800;
                    
int month = maanedValoer % 12 + 1;
                    DBCommandWrapper cmdWrapper 
= db.GetStoredProcCommandWrapper("sp_OpretRapportFraSkabelon");
                    cmdWrapper.AddInParameter(
"@CVR", DbType.String,CVR);
                    cmdWrapper.AddInParameter(
"@Year", DbType.Int32,year);
                    cmdWrapper.AddInParameter(
"@Month", DbType.Int32,month);
                    cmdWrapper.AddParameter  (
"RetVal",DbType.Int32,ParameterDirection.ReturnValue,"",DataRowVersion.Current,null);
                    db.ExecuteNonQuery(cmdWrapper);
                    
int result = (int)cmdWrapper.GetParameterValue("RetVal");
                    
return (result == 0);
                }

                
catch(PensamDBException ex)
                
{
                    
throw ex;
                }

                
catch(Exception ex)
                
{
                    
// Rollback transaction 
                    transaction.Rollback();
                    
throw new PensamDBException("Fejl i opret ny indebertning fra a older one",ex);
                }
 
                
finally
                
{
                    connection.Close(); 
                }

            }

        }