一、配置Data block所需参数
1,应用程序的配置文件(*.exe.config或者*.dll.config或者Web.config)
使用Data access block<?xml version="1.0" encoding="utf-8" ?>
使用Data access block
<configuration>
使用Data access block  
<configSections>
使用Data access block    
<section name="enterpriselibrary.configurationSettings" type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler, Microsoft.Practices.EnterpriseLibrary.Configuration" />
使用Data access block  
</configSections>
使用Data access block  
<enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultSection="" applicationName="Application" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
使用Data access block  
<configurationSections>
使用Data access block    
<configurationSection name="dataConfiguration" encrypt="false">
使用Data access block      
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="dataConfiguration.config" />
使用Data access block      
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
使用Data access block        
<includeTypes />
使用Data access block      
</dataTransformer>
使用Data access block    
</configurationSection>
使用Data access block  
</configurationSections>
使用Data access block  
<keyAlgorithmStorageProvider xsi:nil="true" />
使用Data access block
</enterpriselibrary.configurationSettings> 
使用Data access block
</configuration>

2,配置数据库连接串(dataConfiguration.config)
使用Data access block<?xml version="1.0" encoding="utf-8"?>
使用Data access block
<dataConfiguration>
使用Data access block  
<xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
使用Data access block    
<enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="InstanceWebinpuy" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
使用Data access block      
<databaseTypes>
使用Data access block        
<databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
使用Data access block      
</databaseTypes>
使用Data access block      
<instances>
使用Data access block        
<instance name="InstanceWebinpuy" type="Sql Server" connectionString="Sql Connection String" />
使用Data access block      
</instances>
使用Data access block      
<connectionStrings>
使用Data access block        
<connectionString name="Sql Connection String">
使用Data access block          
<parameters>
使用Data access block            
<parameter name="database" value="BMS_Webinput" isSensitive="false" />
使用Data access block            
<parameter name="Integrated Security" value="False" isSensitive="false" />
使用Data access block            
<parameter name="server" value="192.168.1.28" isSensitive="false" />
使用Data access block          
</parameters>
使用Data access block        
</connectionString>
使用Data access block      
</connectionStrings>
使用Data access block    
</enterpriseLibrary.databaseSettings>
使用Data access block  
</xmlSerializerSection>
使用Data access block
</dataConfiguration>

二、执行Sql语句
使用Data access blockpublic string GetCustomerList()
        }

三、调用存储过程
1、插入新记录并从存储过程获取返回值
存储过程:
使用Data access blockCreate   PROCEDURE usp_AddGroup
使用Data access block 
@StaffID VARCHAR(36),
使用Data access block 
@GroupName VARCHAR(40),
使用Data access block 
@Count  INT
使用Data access block
AS
使用Data access block 
IF EXISTS(SELECT * FROM StaffGroup WHERE StaffID=@StaffID AND GroupName=@GroupName)
使用Data access block  
RETURN 1
使用Data access block 
ELSE
使用Data access block  
INSERT StaffGroup (GroupName,StaffID,MaxCount) VALUES(@GroupName,@StaffID,@Count)
使用Data access block 
RETURN @@ERROR
使用Data access block
GO

调用代码:
使用Data access blockprivate void button4_Click(object sender, System.EventArgs e)
        }

2、返回记录集并获取存储过程返回值
存储过程:
使用Data access blockCREATE procedure usp_GetValidStaffs
使用Data access block            
AS
使用Data access block                
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
使用Data access block                
RETURN 8
使用Data access block            
GO

调用代码:
使用Data access blockprivate void button5_Click(object sender, System.EventArgs e)
        }

3、返回记录集并通过输出参数获取返回值
存储过程:
使用Data access blockCREATE procedure usp_GetValidStaffs
使用Data access block                
@Count INT OUTPUT
使用Data access block            
AS
使用Data access block                
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
使用Data access block                
SET  @Count = 8
使用Data access block            
GO

调用代码:
使用Data access blockprivate void button6_Click(object sender, System.EventArgs e)
        }

4、DataRearder与输出参数
存储过程:
使用Data access blockCREATE procedure usp_GetValidStaffs
使用Data access block                
@Count INT OUTPUT
使用Data access block            
AS
使用Data access block                
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
使用Data access block                
SET  @Count = 8
使用Data access block            
GO

调用代码:
使用Data access blockprivate void button8_Click(object sender, System.EventArgs e)
        }

5、DataRearder与返回值
存储过程:
使用Data access blockCREATE procedure usp_GetValidStaffs
使用Data access block            
AS
使用Data access block                
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
使用Data access block                
RETURN 8
使用Data access block            
GO

调用代码:
使用Data access blockprivate void button7_Click(object sender, System.EventArgs e)
        }

四、事务处理:
使用Data access blockpublic static bool OpretRapportFraskabelon (string CVR, int maanedValoer)
        }

相关文章: