Geeks With Blogs
Fórmulas e Cenas Object Reference Not Set to an Instance of an Object C#
Entity Framework, Insert Fail
When you are inserting into a table using entity framework, on rare occasions you might get the following error: {System.Data.OptimisticConc... Store update, insert, or delete statement affected an unexpected number of rows (0) This happened to me because of an "instead of INSERT" trigger that was active on the page. It turns out that EF does not go well with triggers, because it fails to get the inserted ID. For me, the solution was to change the trigger so that the last executed code ......

Posted On Tuesday, January 22, 2013 10:35 AM

How to select distinct rows from a DataTable
DataView view = new DataView(table);DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...); Source: ......

Posted On Tuesday, October 2, 2012 11:53 AM

How to: Use like '%text%moretext%' using LinqToEntities

Simple and direct:

myContainer.myEntity.Where("it.myField LIKE '%' + @searchTerm + '%'", new ObjectParameter("searchTerm", myQueryText));

Posted On Wednesday, April 18, 2012 8:52 AM

string.Format input string was not in a correct format
If you have a "{" or "}" inside a string when using string.format you will get the error mentioned in the title. To fix this you must double the charater. Error Example: string teste = string.Format(" This is a {teste} {0} ", mystring); Correct Example: string teste = string.Format(" This is a {{teste}} {0} ", mystring);v ......

Posted On Monday, December 19, 2011 9:46 AM

How to execute a javascript function every time an updatepanel executes an async postback

<script type="text/javascript" language="javascript">


        function refresh() { //Your code here; }




Posted On Tuesday, September 20, 2011 4:57 AM

How to: Upload a file using FTP
FileInfo fileInf = new FileInfo("c:\myfile.txt"); FtpWebRequest reqFTP = (FtpWebRequest)FtpWebReques... Uri("ftp://myFTPSite/myfile... reqFTP.Credentials = new NetworkCredential("myUser",... "myFTPDomain"); reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.Uploa... reqFTP.UseBinary = true; reqFTP.ContentLength = fileInf.Length; int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; FileStream fs = fileInf.OpenRead(); try { Stream strm = ......

Posted On Thursday, October 7, 2010 11:31 AM

How to: Download a file using FTP
FileStream outputStream = new FileStream("c:\myfilefolder... FtpWebRequest reqFTP = (FtpWebRequest)FtpWebReques... Uri("ftp://myFTPSite/file.t... reqFTP.Method = WebRequestMethods.Ftp.Downl... reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential("myUser",... FtpWebResponse response = (FtpWebResponse)reqFTP.GetR... Stream ftpStream = response.GetResponseStream(); int bufferSize = 2048; int readCount; byte[] buffer = new byte[bufferSize]; ......

Posted On Thursday, October 7, 2010 11:24 AM

How to: List Files from an FTP Location
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebReques... Uri("ftp://myFTPURL/")); reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential("myUser", "myPassword", "FTPDomain"); reqFTP.Method = WebRequestMethods.Ftp.ListD... WebResponse response = reqFTP.GetResponse(); StreamReader reader = new StreamReader(response.GetRe... string line = reader.ReadLine(); while (line != null) { line = reader.ReadLine(); } reader.Close(); response.Close(); Enjoy :) ......

Posted On Thursday, October 7, 2010 11:17 AM

How to: Export A Class to XML
The scenario: Imagine someone asks you to create an XML file with some data structure. The approuch: There are several ways to achieve this, the fastest and less time comsuming is to create a class structure that represents the XML structure you need, fill in with the data and them serialize it to a string and save it to a file. The Implementation: Lets say you need a single node, followed by an array of nodes. Class Definition: public class MyNode { [XmlElementAttribute("code")] public int code; ......

Posted On Tuesday, August 17, 2010 10:54 AM

Linq error: MSDTC on server 'servername' is unavailable
Occasionally an application that I am working on throws the above error... After trying to fix my code for a bit, and not finding the problem I googled a bit and discovered that this error is caused by a windows service that must be running. So, if you ever encounter this error, you must turn on the 'Distributed Transaction Coordinator' in order to solve it. Hope this helps. Original source: ......

Posted On Wednesday, August 11, 2010 6:39 AM

Copyright © Sglima | Powered by: | Join free