一、配置Data block所需参数
1,应用程序的配置文件(*.exe.config或者*.dll.config或者Web.config)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings" type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler, Microsoft.Practices.EnterpriseLibrary.Configuration" />
</configSections>
<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">
<configurationSections>
<configurationSection name="dataConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="dataConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
</configurationSections>
<keyAlgorithmStorageProvider xsi:nil="true" />
</enterpriselibrary.configurationSettings>
</configuration>
2,配置数据库连接串(dataConfiguration.config)
<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<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">
<databaseTypes>
<databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</databaseTypes>
<instances>
<instance name="InstanceWebinpuy" type="Sql Server" connectionString="Sql Connection String" />
</instances>
<connectionStrings>
<connectionString name="Sql Connection String">
<parameters>
<parameter name="database" value="BMS_Webinput" isSensitive="false" />
<parameter name="Integrated Security" value="False" isSensitive="false" />
<parameter name="server" value="192.168.1.28" isSensitive="false" />
</parameters>
</connectionString>
</connectionStrings>
</enterpriseLibrary.databaseSettings>
</xmlSerializerSection>
</dataConfiguration>
二、执行Sql语句
public string GetCustomerList()
}
三、调用存储过程
1、插入新记录并从存储过程获取返回值
存储过程:
Create PROCEDURE usp_AddGroup
@StaffID VARCHAR(36),
@GroupName VARCHAR(40),
@Count INT
AS
IF EXISTS(SELECT * FROM StaffGroup WHERE StaffID=@StaffID AND GroupName=@GroupName)
RETURN 1
ELSE
INSERT StaffGroup (GroupName,StaffID,MaxCount) VALUES(@GroupName,@StaffID,@Count)
RETURN @@ERROR
GO
调用代码:
private void button4_Click(object sender, System.EventArgs e)
}
2、返回记录集并获取存储过程返回值
存储过程:
CREATE procedure usp_GetValidStaffs
AS
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
RETURN 8
GO
调用代码:
private void button5_Click(object sender, System.EventArgs e)
}
3、返回记录集并通过输出参数获取返回值
存储过程:
CREATE procedure usp_GetValidStaffs
@Count INT OUTPUT
AS
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
SET @Count = 8
GO
调用代码:
private void button6_Click(object sender, System.EventArgs e)
}
4、DataRearder与输出参数
存储过程:
CREATE procedure usp_GetValidStaffs
@Count INT OUTPUT
AS
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
SET @Count = 8
GO
调用代码:
private void button8_Click(object sender, System.EventArgs e)
}
5、DataRearder与返回值
存储过程:
CREATE procedure usp_GetValidStaffs
AS
Select * from staff where Isdelete = 0 and ShowOnHomePage=1
RETURN 8
GO
调用代码:
private void button7_Click(object sender, System.EventArgs e)
}
四、事务处理:
public static bool OpretRapportFraskabelon (string CVR, int maanedValoer)
}
相关文章: