مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

iran

عضویت از 1394/01/31

تبدیل کد از adoبه linq

  • پنجشنبه 4 شهریور 1395
  • 10:10
تشکر میکنم

سلام
کد زیر را چگونه می توانم به linq تبدیل کنیم

private void BindGrid()
        {
            string constring = @"Data Source=.;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=123";
            using (var con = new SqlConnection(constring))
            {
                using (var cmd = new SqlCommand("aaaaa", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    using (var sda = new SqlDataAdapter(cmd))
                    {
                        using (var dt = new DataTable())
                        {
                            sda.Fill(dt);
                            radGridView1.DataSource = dt;
                        }
                    }
                }
            }
        }

 

پاسخ های این پرسش

تعداد پاسخ ها : 5 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • پنجشنبه 4 شهریور 1395
  • 11:44

کوئری رو قرار بدید تا بتونیم معادل رو بهتون بدیم

برای Provider هم باید از Entity یا LinqtoSql استفاده کنید

کاربر سایت

iran

عضویت از 1394/01/31

  • پنجشنبه 4 شهریور 1395
  • 11:58

باسلام


ALTER proc [dbo].[aaaaa]
as
begin
declare @colname nvarchar(max) =
 N'
select 
distinct(s1.DatePr) as ''تاریخ'',s1.Dayname,s1.StatusDate,
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=7
)as  ['+(select Name from Sentinel_WatchType where TypeID=7) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=26
)as ['+(select Name from Sentinel_WatchType where TypeID=26) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=27
)as ['+(select Name from Sentinel_WatchType where TypeID=27) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=28
)as ['+(select Name from Sentinel_WatchType where TypeID=28) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=29
)as ['+(select Name from Sentinel_WatchType where TypeID=29) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=30
)as ['+(select Name from Sentinel_WatchType where TypeID=30) + '],
(
select Namefamily   from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=31
)as ['+(select Name from Sentinel_WatchType where TypeID=31) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=32
)as ['+(select Name from Sentinel_WatchType where TypeID=32) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=33
)as ['+(select Name from Sentinel_WatchType where TypeID=33) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=34
)as ['+(select Name from Sentinel_WatchType where TypeID=34) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=35
)as ['+(select Name from Sentinel_WatchType where TypeID=35) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=38
)as ['+(select Name from Sentinel_WatchType where TypeID=38) + '],
(
select Namefamily  from [dbo].[test] s2  
where s2.DatePr=s1.DatePr and s2.Sentinel_WatchTypeID=39
)as ['+(select Name from Sentinel_WatchType where TypeID=39) + ']

from [dbo].[test]  s1
';
exec sp_executesql @colname
end

 

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • پنجشنبه 4 شهریور 1395
  • 12:00
کاربر سایت

iran

عضویت از 1394/01/31

  • پنجشنبه 4 شهریور 1395
  • 12:04

سلام

استاد اینها را می دانم اما مشکل من اینه که ایندفعه spیک کوئری داینامیک است 

با روش adoتنوستم انجام بدهم اما با linq نمی تونم

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • پنجشنبه 4 شهریور 1395
  • 12:09

Linq سمت سی شارپ هست و به SP مربوط نمیشه

اگر میخواهید SP فراخوانی کنید میتونید توسط EntityFramework به سادگی فراخوانی کنید

در سایت چند نمونه هست

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)