Thursday, October 27, 2011

Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'int?'

When you're executing a Save on your DataContext using EF, and get this error:

Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'int?'

You may want to try adding a SingleOrDefault or FirstOrDefault to the end of your SPROC call to close the transaction before you save.

BAD
int? rc = myContext.myProc(myParameter);
myContext.Save();

GOOD
int? rc = myContext.myProc(myParameter).FirstOrDefault();
myContext.Save();

Sunday, November 15, 2009

Text Wrap in GridViews

If you want to make your text wrap in a GridView control, just add the style WORD-BREAK:BREAK-ALL.
protected void gridViewCustomer_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("style", "WORD-BREAK:BREAK-ALL");
}
{

Friday, November 13, 2009

Read XML doc with xmlns using XDocument

Sample Xml File County.xml

<root xmlns="nameSpace">
<county>
<group name="Sutter">
<group name="Yuba">
<group name="Placer">
</group>
</group>
<root>

-----------------------------------------------------------

//C#
XDocument xDoc = XDocument.Load("Country.xml");
XNamespace ns = xDoc.Root.Name.Namespace;

//adding the namespace infront of the XName will allow you to access the node.
var elements = xDoc..Element(ns+"root").Element(ns+"County").Descendants(ns+"Group");

foreach (var element in elements)
{
Console.Write(element.Attribute("name").ToString());
}




Tuesday, September 22, 2009

siteMapNode target="_blank"

Don't waste your time adding a target="_blank" attribute in your sitemapNode, IT DOESN'T WORK. There is a work around though. Add JavaScript to open your link in a new page.

Example:
(Will not work)<sitemapnode url="http://www.google.com" title="Google" target="_blank">

(WORKS!)<sitemapnode href="javascript:var w=window.open('http://www.google.com','google');" title="Google" />

Monday, July 20, 2009

Great Sql Server Plugin

T-Sql CRUD Code Generator


If you're like me, you want save time when coding. If there is a mundane task that you can teach a monkey to do, why wast time and do it your self. I found a great plug-in for Sql Server Management Studio that lets you generate CRUD statements for your tables. Just right click on your table in Object Explorer and choose create CRUD.

A big thank you to Mladen Prajdić, the developer who created this useful tool. Go to his website, download his tool, and click on some ads.

http://www.ssmstoolspack.com/Main.aspx

Tuesday, June 2, 2009

Installing Visual Studio 2008 SP1

Be Patient! Installation takes a long time!

I made the mistake of canceling installing several times because I thought it was hanging. Nope, this install just takes a very long time. Just wanted to warn everyone that you need to be patient. The installer progress screen will be on "Installing VS90sp1-KB945140-X86-ENU" for a while. Just wait it out.

Saturday, April 25, 2009

The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'. However, the current database schema i

If you are migrating your site to a new server and generated a create table script of all the asp.net membership tables, It's most likely that your aspnet_SchemaVersions table is empty. If you populate aspnet_SchemaVersions table with the following values, you should be good to go.


Feature CompatibleSchemaVersion IsCurrentVersion

common 1 1
health monitoring 1 1
membership 1 1
personalization 1 1
profile 1 1
role manager 1 1