本文整理汇总了C#中System.Data.SqlClient.SqlCommand.set_CommandText方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.set_CommandText方法的具体用法?C# SqlCommand.set_CommandText怎么用?C# SqlCommand.set_CommandText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.set_CommandText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}