Linq to SQL - add days between dates in the WHERE clause

by Gondar 28. November 2010 16:14

where "dc" is my DataBase DataContext

from a in dc.TableA
where (a.AddProductDate - DateTime.Now).TotalDays < 10
select a;

hope it helps :)

 

Tags: , ,

Linq

Linq to SQL - Join

by Gondar 28. November 2010 16:01

var query = from a in dc.TableA
   join b in dc.TableB on a.ColumnId equals b.ColumnId
   join c in dc.TableC on a.ColumnId equals c.ColumnId
   orderby a.Name, a.LastName descending
   select new { a, b, c };

foreach (var q in query)
{
   Console.Write(string.Format("Hello {0} {1}", q._a.Name, q._a.LastName));
}

hope it helps ;)

Tags: ,

Linq

paging using DataPager, not in XAML.. in code behind :)

by Gondar 25. November 2010 00:25

if we can choose, i choose to write my code in the code behind.. its better than have to recover files in svn, or compare the file with older versions.. who works with designers daily understand what i´m saying :D

my result:

XAML:

<sdk:DataGrid x:Name="dgResult"/>
<sdk:DataPager x:Name="dgResultPager" Margin="0,-1,0,0" PageSize="3" Source="{Binding Path=ItemsSource, ElementName=dgResult}" />

Code Behind:

public Entity()
{
    InitializeComponent();
    Loaded += new RoutedEventHandler(Entity_Loaded);
}

void Entity_Loaded(object sender, RoutedEventArgs e)
{
    BdDomainContext dc = new BdDomainContext();
    PagedCollectionView tempListView = new PagedCollectionView(dc.tb_Entities);
    dgResult.ItemsSource = tempListView;
    dc.Load(dc.GetTb_EntitiesQuery());
}

credits: http://msdn.microsoft.com/en-us/library/system.windows.data.pagedcollectionview%28VS.95%29.aspx

hope it helps ;)

 

Tags: ,

Silverlight

Generate QR (quick response) Code

by Hugo 25. October 2010 12:50

http://qrcode.kaywa.com/

Just type the url (http://blog.tekdrop.com),
click generate it, and then: 

if you want to try it on your PC you can use the following program:

http://www.dansl.net/blog/?p=256

if you want to try on your mobile you can use:

http://reader.kaywa.com/

Simple!

Tags: ,

Interests

how to get next birthdays between too dates ?

by Gondar 1. October 2010 00:02

using the DATEPART and DAYOFYEAR is very simple..

select Name
from tb_UserInfo
where datepart(dayofyear, BirthDate) between datepart(dayofyear,getdate()) and datepart(dayofyear, dateadd(day,7,getdate()))

in my example, I wanted to get the the days between a week, seven days.

hope it helps.

Tags: , ,

Sql Server

center a div (vertically and horizontally)

by Hugo 28. September 2010 16:43

just add the following class to your CSS

<style type="text/css">
#centerdiv
{
position:absolute;
top: 50%;
left: 50%;
width:690px;
height:542px;
margin-top: -271px; /* negative half height*/
margin-left: -345px; /* negative half width*/
}
</style>

then

<div class="centerdiv">lalalala</div>

Tags: , ,

HTML

ERROR: 'System.Data.TypedTableBase`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

by Gondar 16. September 2010 11:42

what does it mean ?

"... Apparently VS 2008 changed the base class for Typed DataTables 3.5 : public partial class SubusersDataTable : global::System.Data.TypedTableBase<SubusersRow> {
2.0: public partial class SubusersDataTable : global::System.Data.DataTable, global::System.Collections.IEnumerable {
 and you need to change all dependant assemblies to target 3.5 framework (if not done yet) and add a reference to assembly 'System.Data.DataSetExtensions, Version=3.5.0.0 ..."

thanks to: http://geekswithblogs.net/mnf/archive/2009/05/10/typed-datatables--base-class-in-vs008.aspx

 

Tags: ,

ASP.Net C#

Floatbox

by Hugo 19. August 2010 10:38

Tags:

HTML

how can I select the rows where some date is between weekdays/weekends ?

by Gondar 4. August 2010 18:57

get the products ordered between Monday/Friday:

select product, price from tb_Order where DATEPART(weekday,OrderDate) between 2 and 6

get the products ordered in weekends:

select product,price from tb_Order where (DATEPART(weekday,OrderDate)=1 or DATEPART(weekday,OrderDate)=7)

why I'm using this values? check this post from Pinal Dave (sqlauthority.com)

Tags:

can i catch a "personalized" error from sql server in a asp.net app?

by Gondar 8. February 2010 15:20

sure, just need to use the RAISERROR in sql server.

in your ASP.Net application, inside a try{...} add your query, and in the catch prepare a label to receive the Error Message, that will be the message from SqlServer.

example:

try
{
DataBase.Execute("declare @temp int" +
"select @temp=0" +
"if @temp=0" +
"RAISERROR('[Error Message]', 16, 1)");
}
catch (Exception ex)
{
lblInfo.Text = ex.Message;
}

after executing this the text of the label will be: [Error Message]

hope it helps.

Tags: , ,

Sql Server

About the author

Something about the author

Month List

Page List