.

The null value cannot be assigned to a member with type System.Guid which is a non-nullable value type

I encountered the following issue and couldn't find any information on the internet on this issue:

The null value cannot be assigned to a member with type System.Guid which
is a non-nullable value type.

Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.

Exception Details:
System.InvalidOperationException: The null value cannot be assigned to a
member with type System.Guid which is a non-nullable value
type.

Source Error:

Line 1690: Kingsweb2DataAccess.Kingsweb2DataClassesDataContext newdb = new Kingsweb2DataAccess.Kingsweb2DataClassesDataContext();

Line 1691: List<Kingsweb2DataAccess.SearchKingsFullListResult> x = (from m in newdb.SearchKingsFullList(KingsHospitalID) select m).ToList();

Line 1692: foreach (string word in words)

After quite a struggle I solved it as follow (which really is bizarre and still unexplained):

 I change:

SELECT *, guidanceType.name as guidanceType, legacyID as refid
FROM  HospitalGuide INNER JOIN
               GuidanceType ON HospitalGuide.GuidanceTypeId = GuidanceType.Id

 To:

SELECT HospitalGuide.*, guidanceType.name as guidanceType, legacyID as refid
FROM  HospitalGuide INNER JOIN
               GuidanceType ON HospitalGuide.GuidanceTypeId = GuidanceType.Id

 and it solved my problem.

 

 

are you sure

add the following attributes:

OnClientClick="if(!confirm('Are you sure?'))return false;"

to your button / link button etc. e.g.

<asp:LinkButton ID="ButtonReset" runat="server" Text="Reset"

onclick="ButtonReset_Click" OnClientClick="if(!confirm('Are you sure?'))return false;" />

 

making checkbox/check box READONLY

The easiest work around I guess is to do a javascript return false on trying to change the value, thus:

onclick="return false;"

Here are the ASP.Net and HTML versions:

<asp:CheckBox ID="Whatever" runat="server" onclick="return false;" />

<input type="checkbox" onclick="return false;" />

Linq to SQL

LINQ to SQL in a nutshell

For LINQ to SQL, remember the Using System.Data.Linq; Using System.Linq;  assembly declaration
this uses System.Core.dll

 

CustomersDataContext dc = new CustomersDataContext();

SELECTING:
var query = from m in dc.Customers
                  where m.LastName = "Brown"
                  order by m.LastName descending
                  select m;

var query = from m in dc.Customers

                  join g in dc.Titles on m.TitleId equals g.Id
                  select m;

var query = (from m in dc.Customers
                  select m).Skip(10).Take(10);

var query = from m in dc.Customers
                  group m by m.Country into g
                  select new { Country = g.Key , Count = g.Count() };

query.Count(), query.Max(m => m.DOB), query.Min(m => m.DOB), query.Ave(m => m.Age), query.Sum(m => m.Balance)

foreach (Customer c in query)
{ … }

GridView1.DataSource = query;
GridView1.DataBind();

 

DELETING:
var query = from m in dc.Customers
                  where m.LastName = "Brown"
                  select m;

dc.Customers.DeleteAllOnSubmit(query);  // to delete all that matches the where filter

var OneCust = dc.Customers.Single (m => m.id = 55);
dc.Customers.DeleteOnSubmit(OneCust);  // to delete just the one customer in OneCust (id=55)

dc.SubmitChanges();

INSERTING:
Customer m = new Customer { FirstName = "pete", LastName = "brown" };
dc.Customers.InsertOnSubmit(m);  // to delete all that matches the where filter
dc.SubmitChanges();

remember to — try { } catch (ChangeConflictException  e) { }

 

 

 

 

More C# Linq2SQL MSDN Examples at:

http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx