Хранить процедуру, а не значение retern
привет в моем проекте проблема когда я хочу прочитать запись с помощью sql datareader
Что я уже пробовал:
using (SqlConnection mysqlConnection = new SqlConnection(this.database.getConnectionString())) { using (SqlCommand mySqlCommand = new SqlCommand("GetDboName", mysqlConnection)) { mySqlCommand.CommandType = CommandType.StoredProcedure; mySqlCommand.Parameters.AddWithValue("@Imei", imei); mysqlConnection.Open(); using (SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader()) { if (!mySqlDataReader.HasRows) { throw new QueryException(1, "Tracker " + imei + " is not registered."); } else { mySqlDataReader.Read(); } } //mysqlConnection.Close(); } }
declare @imei nvarchar(100)=869170031585095 DECLARE @DatabaseName NVARCHAR(MAX)=null, @SQL NVARCHAR(MAX); select @DatabaseName= DboName from [CentralRelation].[dbo].[TrackingMaster] where Imei=869170031585095 SET @SQL = N'USE ' + QUOTENAME(@DatabaseName) +' SELECT dbo.LastLogDevice.time, dbo.Carrier.carrierID, dbo.Carrier.carrierTypeFId, dbo.Carrier.companyFId, dbo.Carrier.orgFId, dbo.Carrier.fleetFid, dbo.Carrier.carrierName, dbo.Carrier.carreiernameonmap, dbo.Carrier.deviceImei, dbo.Carrier.displayorhidenonmap, dbo.Carrier.zoneFId, dbo.Carrier.SimNumber, dbo.Carrier.Status, dbo.Carrier.PelackNumber, dbo.Carrier.apnName, dbo.Carrier.apnUserName, dbo.Carrier.apnPassword, dbo.Carrier.createdOn, dbo.Carrier.expiresOn, dbo.Carrier.Lastedit ,(select CompanyName from [CentralAlcazer].[dbo].[Tracker] as t1 where t1.DeviceImei='+@imei+') as dboname FROM dbo.Carrier INNER JOIN dbo.LastLogDevice ON dbo.Carrier.carrierID = dbo.LastLogDevice.carrierFId WHERE(dbo.Carrier.deviceImei ='+ @imei+') AND(dbo.Carrier.createdOn < GETDATE()) AND(dbo.Carrier.expiresOn > GETDATE()) AND(dbo.Carrier.Status = 1)'; --PRINT(@SQL); EXECUTE(@SQL);
F-ES Sitecore
А что у тебя за вопрос?