Showing posts with label asp net. Show all posts
Showing posts with label asp net. Show all posts

Tuesday, July 19, 2016

The entity type List`1 is not part of the model for the current context

where db is List

db.Entry(bd).State = EntityState.Modified;

DbContext.Entry(object) expects a single object, not a collection.

so use a loop instead

foreach (var item in bd)
{
    db.Entry(item).State = EntityState.Modified;
}

Sunday, January 24, 2016

Tuesday, January 19, 2016

How to store string in a cookie and retrieve it

Writing a cookie

HttpCookie myCookie = new HttpCookie("MyTestCookie");
DateTime now = DateTime.Now;
 
// Set the cookie value.
myCookie.Value = now.ToString();
// Set the cookie expiration date.
myCookie.Expires = now.AddYears(50); // For a cookie to effectively never expire
 
// Add the cookie.
Response.Cookies.Add(myCookie);

Reading a cookie

HttpCookie myCookie = Request.Cookies["MyTestCookie"];
 
// Read the cookie information and display it.
if (myCookie != null)
    Response.Write("<p>" + myCookie.Name + "<p>" + myCookie.Value);
else
    Response.Write("not found");

why cookies are always null after postback

private static string GetCookie(string name)
{
    return HttpContext.Current.Request != null ? HttpContext.Current.Request.Cookies[name].Value : string.Empty;
}
 
private static void SetCookie(string name, string value)
{
    HttpContext.Current.Request.Cookies[name].Value = value;
    HttpContext.Current.Request.Cookies[name].Expires = DateTime.Now.AddDays(100);
}

Tuesday, July 14, 2015

Monday, July 13, 2015

How to get sql server bak file logical name

RESTORE FILELISTONLY 
FROM  DISK = N'path to bak file' 
WITH  FILE = 1 
GO

Use WITH MOVE to identify a valid location for the file.

USE [master]
GO
RESTORE DATABASE [DBName] 
FROM  DISK = N'Path to BAK File' 
WITH  FILE = 1,  
MOVE N'Logical File Name' TO N'New Path to mdf file',  
MOVE N'Logical File Log Name' TO N'New Path to log file',  
NOUNLOAD,  REPLACE,  STATS = 1
GO


To get logical file list

RESTORE FILELISTONLY 
FROM  DISK = N'path to bak file' 
WITH  FILE = 1 
GO

Sunday, June 14, 2015

crystal report for visual studio 2015 / dot net framework 4.6

just copy existing framework folder in aspnet_client\system_web folder and the rename it to 4_81 or whatever version you have installed and your are done
To Check your version click here
http://w3dproblems.dcense.com/2015/09/what-net-version-are-you-running-20-45.html

Tuesday, May 19, 2015

LINQ: SqlDateTime overflow. Must be between ...

WHEN a NULL value to passed to a non null datetime field using LINQ datasource. If the field is autogenerated make sure to mark as autogenerated in LINQ DBML designer else pass the value using a parameter

Thursday, May 14, 2015

Get all asp net listview items in array

var rows = [];
$('#<%: lvStudents.ClientID %>_itemPlaceholderContainer tr:gt(1)').each(function (i, v) {
    var row = $(this);
    rows.push(row);
});
if InsertItemPosition="LastItem"
gt(1)
else if InsertItemPosition="FirstItem" 
gt(2)

Wednesday, May 13, 2015

How to update rows randomly

update dbo.Table 
set Field = Value 
where Id in ( select top 50 percent id from dbo.Table order by NEWID() )

Handling Multiple FULL OUTER JOIN in sql

SELECT A.column2 , B.column2 , C.column2 FROM ( 
 (SELECT month, column2 FROM table1) 

 FULL OUTER JOIN 
 (SELECT month, column2 FROM table2) 
B on A.month= B.month 
 FULL OUTER JOIN 
 (SELECT month, column2 FROM table3) 
C on ISNULL(A.month, B.month) = C.month )

How to update rows with a random date

UPDATE table SET datetimecol = DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0)

How to convert IList to IQuerable

IQueryable query = new List() { 1, 2, 3, 4, 5}.AsQueryable();

How to check if IQueryable result set is null or empty

list will never be null with LINQ; it will simply represent an "empty collection" if need be. The way to test is with the Any extension method:
if (list.Any()) 
{
// list has at least one item
}

Friday, May 8, 2015

Value cannot be null. Parameter name: panelsCreated[0] asp net

Switch scriptmanager mode to release

<asp:ScriptManager runat="server" ScriptMode="Release" />

InvalidOperationException: Could not find UpdatePanel with ID asp net

Change ClientIDMode on UpdatePanels to AutoID

<asp:UpdatePanel runat="server" ClientIDMode="AutoID">

Thursday, April 30, 2015

Monday, April 20, 2015

Using DataBinder.Eval in the RowDataBound Event asp net gridview

decimal totalAmount = 0;
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
 totalAmount += Decimal.Parse(DataBinder.Eval(e.Row.DataItem, "Amount").ToString());
}
}