C#打包SQL数据库部署安装
参考《ASP.NET与SQL一起打包部署安装》,这篇文章是针对VB.NET与SQL 一起打包的,但是我使用的是C#,当然只要修改一下主要安装类库就行了!C#的类库代码如下:DBCustomAction.cs
using System;
using System.Collections;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Reflection;
namespace PMS
{
/// <summary>
/// DBCustomAction 的摘要说明。
/// </summary>
[RunInstaller(true)]
public class DBCustomAction : System.Configuration.Install.Installer
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public DBCustomAction()
{
// 该调用是设计器所必需的。
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何初始化
}
private void ExecuteSql(string conn,string DatabaseName,string Sql)
{
SqlConnection mySqlConnection=new SqlConnection(conn);
SqlCommand Command=new SqlCommand(Sql, mySqlConnection);
mySqlConnection.Open();
mySqlConnection.ChangeDatabase(DatabaseName);
try
{
Command.ExecuteNonQuery();
}
finally
{
//close Connection
mySqlConnection.Close();
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
&nb
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
1.先启用 xp_cmdshell 扩展存储过程:
Use Master
GO
Exec sp_configure 'show advanced options', 1
GO
Reconfigure;
GO
sp_configure 'xp_cmdshell', 1
GO
Reconfigure;
GO
(注:因为xp_cmdshell是高级选项,所以这里启动xp_cmdshell,需要先将 show advanced ......
SELECT CONVERT(varchar(100), CAST(@testFloat AS decimal(38,2)))
SELECT STR(@testFloat, 38, 2)
从Excel中导入到sql2000,有一列“联系方式”变成了float类型,我想转换成nvarchar类型,用下面的语句
select convert(nvarchar(30),convert(int,联系方式)) from employee
go
//数据溢出,不行!
select ......
Sql常见面试题(总结)
0.如何删除一个拥有比较多的数据的表
如果该表所在的数据库拥有较少的表,可以先将其余表导出去,然后分离数据库,在删除,新建一个同名数据库,将其余表再次导入。
1.用一条SQL语句 查询出每门课都大于80分的学生姓名
name kecheng fenshu
张三 语文 &n ......