网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

sqlserver1,sqlserver15151

sqlserver数据库链接1

using System;

创新互联建站长期为1000多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为嫩江企业提供专业的网站制作、做网站嫩江网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。

using System.Data;

using System.Xml;

using System.Data.SqlClient;

using System.Collections;

namespace DataBase.Data.SqlClient

{

public sealed class SqlHelper

{

#region private utility methods constructors

private SqlHelper() { }

private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)

{

foreach (SqlParameter p in commandParameters)

{

if ((p.Direction == ParameterDirection.InputOutput) (p.Value == null))

{

p.Value = DBNull.Value;

}

command.Parameters.Add(p);

}

}

private static void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues)

{

if ((commandParameters == null) || (parameterValues == null))

{

return;

}

if (commandParameters.Length != parameterValues.Length)

{

throw new ArgumentException("Parameter count does not match Parameter Value count.");

}

for (int i = 0, j = commandParameters.Length; i j; i++)

{

commandParameters[i].Value = parameterValues[i];

}

}

private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters)

{

if (connection.State != ConnectionState.Open)

{

connection.Open();

}

command.Connection = connection;

command.CommandText = commandText;

command.CommandTimeout = 20;

if (transaction != null)

{

command.Transaction = transaction;

}

command.CommandType = commandType;

if (commandParameters != null)

{

AttachParameters(command, commandParameters);

}

return;

}

#endregion private utility methods constructors

#region ExecuteNonQuery

public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText)

{

return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null);

}

public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

using (SqlConnection cn = new SqlConnection(connectionString))

{

cn.Open();

return ExecuteNonQuery(cn, commandType, commandText, commandParameters);

}

}

public static int ExecuteNonQuery(string connectionString, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName);

}

}

public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText)

{

return ExecuteNonQuery(connection, commandType, commandText, (SqlParameter[])null);

}

public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

SqlCommand cmd = new SqlCommand();

PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);

int retval = cmd.ExecuteNonQuery();

cmd.Parameters.Clear();

return retval;

}

public static int ExecuteNonQuery(SqlConnection connection, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName);

}

}

public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText)

{

return ExecuteNonQuery(transaction, commandType, commandText, (SqlParameter[])null);

}

public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

SqlCommand cmd = new SqlCommand();

PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);

int retval = cmd.ExecuteNonQuery();

cmd.Parameters.Clear();

return retval;

}

public static int ExecuteNonQuery(SqlTransaction transaction, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName);

}

}

#endregion ExecuteNonQuery

#region ExecuteDataSet

public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText)

{

return ExecuteDataset(connectionString, commandType, commandText, (SqlParameter[])null);

}

public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

using (SqlConnection cn = new SqlConnection(connectionString))

{

cn.Open();

return ExecuteDataset(cn, commandType, commandText, commandParameters);

}

}

public static DataSet ExecuteDataset(string connectionString, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName);

}

}

public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText)

{

return ExecuteDataset(connection, commandType, commandText, (SqlParameter[])null);

}

public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

SqlCommand cmd = new SqlCommand();

PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

cmd.Parameters.Clear();

return ds;

}

public static DataSet ExecuteDataset(SqlConnection connection, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteDataset(connection, CommandType.StoredProcedure, spName);

}

}

public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText)

{

return ExecuteDataset(transaction, commandType, commandText, (SqlParameter[])null);

}

public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

SqlCommand cmd = new SqlCommand();

PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

cmd.Parameters.Clear();

return ds;

}

public static DataSet ExecuteDataset(SqlTransaction transaction, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteDataset(transaction, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteDataset(transaction, CommandType.StoredProcedure, spName);

}

}

#endregion ExecuteDataSet

#region ExecuteDatatable

public static DataTable ExecuteDatatable(string connectionString, CommandType commandType, string commandText)

{

return ExecuteDatatable(connectionString, commandType, commandText, (SqlParameter[])null);

}

public static DataTable ExecuteDatatable(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

using (SqlConnection cn = new SqlConnection(connectionString))

{

cn.Open();

return ExecuteDatatable(cn, commandType, commandText, commandParameters);

}

}

public static DataTable ExecuteDatatable(string connectionString, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteDatatable(connectionString, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteDatatable(connectionString, CommandType.StoredProcedure, spName);

}

}

public static DataTable ExecuteDatatable(SqlConnection connection, CommandType commandType, string commandText)

{

return ExecuteDatatable(connection, commandType, commandText, (SqlParameter[])null);

}

public static DataTable ExecuteDatatable(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

SqlCommand cmd = new SqlCommand();

PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable();

da.Fill(dt);

cmd.Parameters.Clear();

return dt;

}

public static DataTable ExecuteDatatable(SqlConnection connection, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteDatatable(connection, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteDatatable(connection, CommandType.StoredProcedure, spName);

}

}

public static DataTable ExecuteDatatable(SqlTransaction transaction, CommandType commandType, string commandText)

{

return ExecuteDatatable(transaction, commandType, commandText, (SqlParameter[])null);

}

public static DataTable ExecuteDatatable(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

SqlCommand cmd = new SqlCommand();

PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable();

da.Fill(dt);

cmd.Parameters.Clear();

return dt;

}

public static DataTable ExecuteDatatable(SqlTransaction transaction, string spName, params object[] parameterValues)

{

if ((parameterValues != null) (parameterValues.Length 0))

{

SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteDatatable(transaction, CommandType.StoredProcedure, spName, commandParameters);

}

else

{

return ExecuteDatatable(transaction, CommandType.StoredProcedure, spName);

}

}

《SQLServer》1. 怎样结束事物?

事务分显示事务和隐式事务,

隐式事务 在SQLServer 语句执行完成就自动结束;

显示事务语法:

BEGIN TRAN/TRANSACTION

--这里写事务内容

callback TRAN/TRANSACTION --回滚事务

commit TRAN/TRANSACTION --提交事务

callback 和commit 都是结束事务的语句,不通之处在于,callback是回滚使用,即事务中所有执行语句都无效化(在事务中某处有错误时使用); commit 是提交事务,即完成所有事务内容。

sqlserver一对一关系怎么建立

你好, 非常高兴为你解答

现在你建了两个表主键都是xuehao, 也就是说学好是1001的在这两个表里都只能存在一条

这就是一对一的关系, 不用再有什么约束,不知道你还想要什么结果, 如果有能举个例子吗


分享文章:sqlserver1,sqlserver15151
当前路径:http://bjjierui.cn/article/hdopos.html

其他资讯