本文整理汇总了C#中System.Data.SqlClient.SqlCommand.set_CommandTimeout方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.set_CommandTimeout方法的具体用法?C# SqlCommand.set_CommandTimeout怎么用?C# SqlCommand.set_CommandTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.set_CommandTimeout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteScalar
public int ExecuteScalar()
{
int result = 0;
using (SqlConnection sqlConnection = new SqlConnection(Constants.Config.ConnectionString))
{
SqlCommand sqlCommand = new SqlCommand(this.Name, sqlConnection);
sqlCommand.set_CommandType(4);
sqlCommand.set_CommandTimeout(120);
IEnumerator enumerator = this.StoredProcParams.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
StoredProcParam storedProcParam = (StoredProcParam)enumerator.get_Current();
sqlCommand.get_Parameters().Add(storedProcParam.ParamID, storedProcParam.ParamValue);
}
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
sqlConnection.Open();
result = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlConnection.Close();
}
return result;
}
示例2: ExecuteDataSet
public DataSet ExecuteDataSet()
{
DataSet dataSet;
using (SqlConnection sqlConnection = new SqlConnection(Constants.Config.ConnectionString))
{
SqlCommand sqlCommand = new SqlCommand(this.Name, sqlConnection);
sqlCommand.set_CommandType(4);
sqlCommand.set_CommandTimeout(120);
IEnumerator enumerator = this.StoredProcParams.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
StoredProcParam storedProcParam = (StoredProcParam)enumerator.get_Current();
sqlCommand.get_Parameters().Add(storedProcParam.ParamID, storedProcParam.ParamValue);
}
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
dataSet = new DataSet();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlDataAdapter.Fill(dataSet);
}
return dataSet;
}
示例3: PrepareCommand
private static System.Data.SqlClient.SqlCommand PrepareCommand(System.Data.SqlClient.SqlTransaction trans, string sql, System.Data.SqlClient.SqlParameter[] parameters)
{
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(sql, Connection, trans);
command.set_CommandType(System.Data.CommandType.Text);
command.set_CommandTimeout(0);
if (parameters != null)
{
command.Parameters.AddRange(parameters);
}
foreach (System.Data.SqlClient.SqlParameter parameter in command.Parameters)
{
if (parameter.get_Value() == null)
{
parameter.set_Value(System.DBNull.Value);
}
if ((parameter.SqlDbType == System.Data.SqlDbType.DateTime) && parameter.get_Value().Equals(new System.DateTime(1, 1, 1)))
{
parameter.set_Value(System.DBNull.Value);
}
}
return command;
}
示例4: ExecuteReturnVal
public int ExecuteReturnVal()
{
int result = 0;
using (SqlConnection sqlConnection = new SqlConnection(Constants.Config.ConnectionString))
{
SqlCommand sqlCommand = new SqlCommand(this.Name, sqlConnection);
sqlCommand.set_CommandType(4);
sqlCommand.set_CommandTimeout(120);
SqlParameter sqlParameter = new SqlParameter("@RETURN", 8);
sqlParameter.set_Direction(6);
sqlCommand.get_Parameters().Add(sqlParameter);
IEnumerator enumerator = this.StoredProcParams.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
StoredProcParam storedProcParam = (StoredProcParam)enumerator.get_Current();
sqlCommand.get_Parameters().Add(storedProcParam.ParamID, storedProcParam.ParamValue);
}
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
sqlConnection.Open();
sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
result = (int)sqlParameter.get_Value();
}
return result;
}
示例5: JnOperationsByHouse
public System.Data.DataTable JnOperationsByHouse(Server srv, System.DateTime dateBeg, System.DateTime dateEnd, CalcOperationGroup opGroup, Organization srvProvider, ServiceTypeOld srvType)
{
System.Data.DataTable table = new System.Data.DataTable();
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(string.Format("Data Source = {0};Initial Catalog = {1};User ID={2};pwd={3}", new object[] { srv.IpAddress, srv.DbName, srv.UserName, srv.UserPwd }));
try
{
connection.Open();
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("", connection);
command.set_CommandTimeout(0);
command.Parameters.Add("@fromDate", System.Data.SqlDbType.DateTime).set_Value(dateBeg);
command.Parameters.Add("@toDate", System.Data.SqlDbType.DateTime).set_Value(dateEnd);
command.Parameters.Add("@operGroupName", System.Data.SqlDbType.VarChar, 0xff).set_Value(opGroup.Name);
command.Parameters.Add("@providerName", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvProvider.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvProvider.ShortName));
command.Parameters.Add("@serviceTypeName", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvType.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvType.ShortName));
command.set_CommandText("\r\n\t\t\t\t\tselect providerName srvProvider, serviceTypeName srvType, sum(summ) summ\r\n\t\t\t\t\t\t--, apartmentAddrName house\r\n\t\t\t\t\t\t, ( case when apartmentAddrLevel = 40 then sn.LocalAddress_ToString(apartmentParentAddrId, 0) \r\n\t\t\t\t\t\t\telse sn.LocalAddress_ToString(apartmentAddrId, 0) end ) house\r\n\t\t\t\t\tfrom sn.JnGroupView\r\n\t\t\t\t\twhere [email protected] and\r\n\t\t\t\t\t\t period>[email protected] and period<@toDate and\r\n\t\t\t\t\t\t (@providerName is null or @providerName=providerName) and\r\n\t\t\t\t\t\t (@serviceTypeName is null or @serviceTypeName=serviceTypeName)\r\n\t\t\t\t\tgroup by providerName, serviceTypeName, apartmentAddrLevel, apartmentParentAddrId, apartmentAddrId");
new System.Data.SqlClient.SqlDataAdapter(command).Fill(table);
}
finally
{
connection.Close();
}
return table;
}
示例6: JnOperations
public System.Data.DataTable JnOperations(Server srv, System.DateTime dateBeg, System.DateTime dateEnd, CalcOperationGroup opGroup, Organization srvProvider, ServiceTypeOld srvType)
{
System.Data.DataTable table = new System.Data.DataTable();
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(string.Format("Data Source = {0};Initial Catalog = {1};User ID={2};pwd={3}", new object[] { srv.IpAddress, srv.DbName, srv.UserName, srv.UserPwd }));
try
{
connection.Open();
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("", connection);
command.set_CommandTimeout(0);
command.Parameters.Add("@operGroup", System.Data.SqlDbType.VarChar, 0xff).set_Value(opGroup.Name);
command.Parameters.Add("@fromDate", System.Data.SqlDbType.DateTime).set_Value(dateBeg);
command.Parameters.Add("@toDate", System.Data.SqlDbType.DateTime).set_Value(dateEnd);
command.Parameters.Add("@serviceProvider", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvProvider.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvProvider.ShortName));
command.Parameters.Add("@serviceType", System.Data.SqlDbType.VarChar, 0xff).set_Value((srvType.Id == 0L) ? ((object) System.DBNull.Value) : ((object) srvType.ShortName));
command.set_CommandText("\r\n\t\t\t\t\tif object_id('tempdb..#t') is not null drop table #t\r\n\r\n\t\t\t\t\tselect ' '+srvProvider srvProvider, \r\n\t\t\t\t\t\t' '+houseHolder houseHolder, \r\n\t\t\t\t\t\t' '+srvType srvType, summ\r\n\t\t\t\t\tinto #t\r\n\t\t\t\t\tfrom sn.GetJnReportByGroup(@operGroup,@fromDate,@toDate,@serviceProvider,@serviceType) t\r\n\t\t\t\t\t--все внутренние суммы\r\n\t\t\t\t\tselect srvProvider, houseHolder, srvType, summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tunion\r\n/*\t\t\t\t\t--итоги поставщику по нескольким управляющим компаниям (строка)\r\n\t\t\t\t\tselect srvProvider, ' Итого' houseHolder, srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvProvider, srvType\r\n\t\t\t\t\thaving count(distinct houseHolder)>1\r\n\t\t\t\t\tunion\r\n\t\t\t\t\t--итоги поставщику по нескольким управляющим компаниям (сумма в конце)\r\n\t\t\t\t\tselect srvProvider, ' Итого' houseHolder, 'ИТОГО' srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvProvider\r\n\t\t\t\t\thaving count(distinct houseHolder)>1\r\n\t\t\t\t\tunion\r\n*/\t\t\t\t\t--итоги по поставщику с одной управляющей компанией (сумма в конце)\r\n\t\t\t\t\tselect srvProvider, houseHolder, 'ИТОГО' srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvProvider, houseHolder\r\n\t\t\t\t\tunion\r\n\t\t\t\t\t--итоги по группам услуг\r\n\t\t\t\t\tselect 'ИТОГО', '' houseHolder, srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\r\n\t\t\t\t\tgroup by srvType\r\n\t\t\t\t\tunion\r\n\t\t\t\t\t--итоги по всей выборке\r\n\t\t\t\t\tselect 'ИТОГО', '' houseHolder, 'ИТОГО' srvType, sum(summ) summ\r\n\t\t\t\t\tfrom #t\t\t\t\t\t\r\n\t\t\t\t");
new System.Data.SqlClient.SqlDataAdapter(command).Fill(table);
}
finally
{
connection.Close();
}
return table;
}