Click here to Skip to main content
15,881,725 members
Everything / Programming Languages / C#

C#

C#

Great Reads

by Wonde Tadesse
The other option will be to use Update Panel ASP.NET control as much as possible. It helps to retain the current position on the page whenever a postback happens to the page.
by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
by Dr. WPF
.NET 3.5 SP1 is here! It's time to break out your DirectX skills. This article provides the information necessary to get started using a new DirectX interop feature in WPF called D3DImage.
by John Atten
OWIN, Katana and Middleware Pipeline in ASP.NET

Latest Articles

by Zijian
Reusable codes for JWT security in business applications
by Mishael Ogo
A look at a simple SQL builder for Dapper
by honey the codewitch
Implementing a simple JSON parser with Visual FA
by Akram El Assas
Functional Programming in C# through Algebra, Numbers, Euclidean Plane and Fractals

All Articles

Sort by Title

C# 

20 Jun 2014 by sucharita dutta
Hi,We have one .NET application deployed in IIS 7. In certain text boxes if we enter special charaters like or &, it is converted to html code as >
20 Jun 2014 by Jafarinejadvazifehkhorani
As Ranjeet said it has happened somewhere in your code , but by using the HttpUtility you can decode it. here is an example :HttpUtility.HtmlEncode(" &"); //result & HttpUtility.HtmlDecode(" &"); //result &
7 Sep 2014 by Member 10973822
Hello everyone, can someone help me with wpf buttonI want to remove the border and button glow effect.my button has an image background, it changes when the mouse hover but the button glows.here is the button code, I'm using visual studio 2010
7 Sep 2014 by Jawad Shairf
you can simply override the default border brush to your own border brush
29 Aug 2016 by KyLim0211
public void binddata() { DataTable dt = new DataTable(); SqlCommand com = new SqlCommand("E_R_GET101", con); com.Parameters.AddWithValue("@Subs_cd", loggeduser.SUBSIDIARY_CD); com.Parameters.AddWithValue("@EMPLOYEE", loggeduser.EmployeeNo); ...
29 Aug 2016 by AdvancedDNA
Instead of trying to BIND to a dataTable, try a DataSet. It's difficult without seeing the rest of your code, but try this:public void binddata() { DataSet ds = new DataSet(); SqlCommand com = new SqlCommand("E_R_GET101", con); ...
3 Oct 2012 by Dev Ashish Jangid
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int i=0; //some code related to i// } } protected void _lblnext_Click(object sender, EventArgs e) { i+=1; //code related to i// }I always...
3 Oct 2012 by solanki.net
Tell me how can u access local variable i in _lblnext_Click()? Explain what u want ?
3 Oct 2012 by Mohd. Mukhtar
Hi Ashish,Please understand the concept of static variable. By default its value set to 0(zero), and its value retain in between function switch call. But here in your case you have declared static variable into the class and assigning the value in page_load event, you want to access...
8 Dec 2010 by karthikkushala
hi am using treeview on load even am binding treeview in that protected void HeadCreationTV_Load(object sender, EventArgs e){ if (!IsPostBack) { GetTreeViewBind(); }}but after saving some values in save button click i have to reload tree once...
8 Dec 2010 by Not Active
If you need to reload the tree after the button click then call GetTreViewBind in the button click handler.You may also want to familiarize yourself with this ASP.NET Page Life Cycle Overview[^]
13 Jun 2014 by Member 10855887
private void btn_addtostore_Click(object sender, EventArgs e) { string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\StoreProdcut.mdb"; string sqlStr = null; OleDbConnection conn = null; OleDbCommand cmd =...
14 Jun 2014 by Debabrata_Das
Hello friend, it seems like you are getting datatype mismatch error as you're trying to concatenate string with an integer value. Try to convert the integer value to string as shown below:for (i = 0; i
1 Dec 2017 by Member 13275563
I have develpoed application in winforms ,but when i open n client machine there are error occured.. " failed to generate a user instance of sql server due to failure in copying database files.the connection will be closed" please give me solution for this .My connection string and code in...
1 Dec 2017 by OriginalGriff
As I said when you posted this earlier: Quote: That string doesn't look right: "Data Source=myPC" is unlikely - you'd normally have an SQL instance name on that as well. "Provider=..." is not a keyword SQL Server supports. Have a look here: Simple SQL Connection String Creation[^] It should...
4 Sep 2013 by Karim2Ahmed
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string cs = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SATDB.mdf;Integrated Security=True;User Instance=True"; using (SqlConnection con = new...
4 Sep 2013 by Mike Meinz
Your error is in this statement:string sql = "GET_FILESTREAM_TRANSACTION_CONTEXT(), SELECT Trial_Addmission.PathName() from Sat";The Microsoft documentation for GET_FILESTREAM_TRANSACTION_CONTEXT[^] shows that it must be used in a Select statement.I've never seen anyone use...
16 May 2013 by Faizymca
protected void btnUpload_Click(object sender, EventArgs e) { if (imgUpload.HasFile) { //Check File is available in Fileupload control and then upload to server path fname = imgUpload.FileName; //spath = @"~\ImgUpload\" +...
16 May 2013 by Sergey Alexandrovich Kryukov
You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown. Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its...
6 Apr 2016 by SURAJ-CDAC
Below is my stub classes generated by wsdl.exe[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)][System.Xml.Serialization.XmlArrayItemAttribute("entries", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]public partial...
6 Apr 2016 by Sergey Alexandrovich Kryukov
Well, XmlSerializer is itself pretty bad and outdated, not fun to deal with (compared, say, to data contract based serialization). But with SOAP you have no choice but playing by SOAP rules, even though they are quite bad. And I don't see where you do it. In particular, I cannot see where you...
10 Dec 2013 by Member 8920414
Here is the link to this articles WPF DataGrid Practical Examples Ran the code with Visual Studio 2012 after installing the WPF Toolkit from add refrences. It compiles, and appears to run, but the buttons do not all work correctly. That buttons that crashes the program are listed...
5 Jun 2023 by Le lance Flamer
Hello, Microsoft Visual Studio 2022 problem: I made a simple program that converts text to an URI and after it gets generated, the program will ask the user if they want to copy the URI to use it somewhere else. I need to use the...
4 Jun 2023 by OriginalGriff
Put the text cursor in the word "Clipboard" and hover the mouse over it - a symbol will appear at the beginning of the line. Click it with the mouse and it'll make suggestions as to what you need to do, which is almost certainly to add a using...
5 Jun 2023 by Alan N
I had something similar recently with VS2017. I can't remember what I did to fix it but most likely I would have done a super clean on the project. I do recall that there was nothing wrong with the source code. Super Clean 1) Delete obj...
5 Jun 2023 by Le lance Flamer
Well, I fixed it myself. The file of the class was the problem: Now I can access all everything as they should. But I still don't understand why it didn't want to work at the first place. Here's the solution: Delete the file then recreate it. It...
18 Jul 2016 by sopi9
I am getting a hit from URL which contain Encoded data. I have came across a situation where this data had + sign which is getting replaced with space and I don't want it to happen.Sample URL: http://xyz.test.com//samplepage.aspx?msg=AUdAR0JGRERBWCMZIxYmJR8fTRY+JR5DRRkxQiA4RUQ=Above URL...
17 Jul 2016 by Kornfeld Eliyahu Peter
By design (and originally) in url space should be encoded to + and not to %20...So the solution is - encode the url by yourself, just as you have done...It will be clear to browser and will not change the data...An other - probably less preferable - option is to base64 encode your data...
17 Jul 2016 by F-ES Sitecore
You need to encode the msg value when you generate\redirect to the url.string url = string.Format("samplepage.aspx?msg={0}", System.Web.HttpUtility.UrlEncode("AUdAR0JGRERBWCMZIxYmJR8fTRY+JR5DRRkxQiA4RUQ="));
7 Dec 2014 by Member 11293760
Hi All,I am facing a problem in Export to Excel from a gridview data.I have the data with forward slash in the data ("/") in one of the columns which is diplaying like a character ”⁄” (slant is more in this case) instead of “/”. The same file is uploading in some other application and...
7 Dec 2014 by Azziet
Export Data with Encoding itResponse.ContentEncoding = Encoding.Unicode;Response.BinaryWrite(Encoding.Unicode.GetPreamble());refer this linkhttp://asheej.blogspot.in/2012/03/how-to-export-gridview-data-to-excel.html[^]
22 Mar 2013 by Kurac1
"A dependent property in a ReferentialConstraint is mapped to a storage-generated column. Column: 'employee_id'."}var emp_assigment = new EMPLOYEES_ASSIGNMENT { from_date =...
22 Mar 2013 by Dave Kreskowiak
The code you posted has nothing to do with the problem. It's probably due to you screwing up the relationship between two tables, invloving the employee_id column of one of the tables.Did you accidentally tell EF that an autonumber column in the database is a Foreign Key column??
1 Jun 2013 by freeheartxiii
Hi, there!I am the new guy on WCF. These days, I'am learning that.I made a empty solution, and this solution contains 4 projects: two c# libs, and two consoles as host and client. the programs ran well, but when client started after host, it raise this info in debug output window: "A first...
2 Jun 2013 by PrissySC
Actually, I will almost bet that while this is the exception that was caught that it is not the problem. You could catch and handle this and ignore it, but you need to find the underlying cause. Check your output, and do a try catch on the block that you suspect. Print out the exception in a...
2 Oct 2014 by Member 9492907
In my application ,i want to Add some dynamic text to my the Current image. So each time When i open the Form the image need to edit and display. First time when i open the Form ,all will work properly.But when i open it for 2 nd time,it won't. I checked all the privileges for the folder...
16 Mar 2014 by Sicppy
I get "A generic error occurred in GDI+" when I try to save a bitmap(that I have opened and edited). It only happens some of the time. I have no idea why this is happening, please help. It occurs at line 162.Thanks in advance,Jordanusing System;using...
16 Mar 2014 by Abhinav S
Check the folder permissions where you are saving the file.You should have permissions to save the file.In addition, ensure that the file does not already exist and is open in another program.
22 Nov 2014 by Krishna7
"A generic error occurred in GDI+" error is occurring in my WPF Editor Application while typing Specific Hindi letters, am using DevExpress RichEditControl for editor (ISM-V6 is using for Hindi Text).How do I solve this?
29 May 2013 by Vahidrsj
I'm using VS2012 and Crystal reports 13.0.5. When i want to print displayed report with print button on crystal report viewer toolbar, its giving me this error: "A StartDocPrinter call was not issued."This article cant help me: http://support.microsoft.com/kb/121074[^] because my printer...
19 Oct 2013 by thatraja
Here solved threadhttp://scn.sap.com/thread/3299135[^]
23 Apr 2016 by m.justice10
Alright I have no idea what is going on here, I can't seem to see why this will not work. { const int CONST_array_max_size = 5; int field_current_student_array_index = 0; decimal[] myArray_StudentGradeDec = new decimal[5]; string[]...
23 Apr 2016 by OriginalGriff
Start by looking at exactly what you are doing here:{ const int CONST_array_max_size = 5; int field_current_student_array_index = 0;... if (this.textBox_StudentName.Text == "") { MessageBox.Show("Error 101: Invalid Student Name"); } else { ...
18 Sep 2011 by ravibulls007
I want to deployment my c#.net project .i want set up that will be created after deployment will installmssql 2005,.net freamwork ,and the server name should be automatically willbe changed on my connection string in my project..So Please Help Me The Step To Do such type of...
18 Sep 2011 by OriginalGriff
You should not include SQL Server in your installation. There are a couple of reasons:0) You can only distribute SQL Server Express for copyright reasons - not SQL Server full version.1) They may already have SQL Server installed on the network. If so, then they will presumably want to use...
8 Mar 2010 by Khaniya
I know how to add files to a project by dragging into solution explorer, and I know how to Add Existing Items.But how does one add a folder + subfolders + files all as links?
9 Mar 2010 by DX Roster
right click to website name and in solution explorer then there is an option add new folder...for add subfolder right click to subfolder and click to add new folder..for add new page or links right click to folder and click on add new item..thanks
9 Mar 2010 by Xmen Real
http://support.microsoft.com/kb/306234[^]
9 Mar 2010 by Khaniya
Again given link by XMen shows for adding link for file, not for folderNow I guess still it is not possible with VS 2008Many Thanks :)
18 May 2012 by deeptibansal
Adding event to Microsoft Outlook through Web Application
25 Apr 2012 by Pete O'Hanlon
When you initialise your cart instance, the number of items in it will be 0. Now, when you add an item to it, just increment count. It's not that hard a task.
13 May 2012 by pavanantkul
hello sir i am getting a run time warning by showing "An error occurred while querying for WMI data:accessed denied"the project title :spyNetcoding lang:c#technologies used:WMI and MQLmy current version of OS is: windows7pls help me[edit]Suject changed, SHOUTING removed -...
23 Jan 2022 by Member 15435636
When I try to add a view, an error message pops up saying "Arithmetic operation resulted in an overflow" What I have tried: I've unsuccessfully tried rebooting my PC, restarting and updating Visual Studio Community 2022
23 Jan 2022 by Member 10163600
I have the same problem with VS2022 Community. Released version. It's an MVC4 project.
23 Jan 2022 by M Imran Ansari
Quote: This issue already reported for fixation. Kindly open your Visual Studio in Admin mode to avoid this exception. I would suggests open as Admin by default. To open you Visual Studio in Admin mode, open VS installed folder. Right click on...
26 May 2010 by Mike Corley
C# (.NET and Mono) library provider for RRDtool
23 Jun 2015 by Shrijith Gopalakrishnan
Console.WriteLine("{0,2} + {1,2} = {2,2}\t{3,2} * {4,2} = {5,4}", i, 100 - i, i + (100 - i), i, 100 - i, i * (100 - i));
23 Jun 2015 by Shrijith Gopalakrishnan
I was wondering what {0,2} meant. Now I realize that the '2' is included just to specify spacing.Console.WriteLine("{0} + {1} = {2}\t{3} * {4} = {5}", i, 100 - i, i + (100 - i), i, 100 - i, i * (100 - i));This code would...
23 Jun 2015 by OriginalGriff
It's a simple output-to-the-console instruction. It outputs 5 values in the form:nn + nn = nn nn * nn = nnThe first parameter (the string) specifies the way the data will be presented, the remaining ones provide the values to show.Each item in curly brackets in the format string...
21 Mar 2013 by Jagadisha_Ingenious
Hi everyone, Can anybody tell me why i get "Cannot access a disposed object" error when i am migrating from 1 form to another without closing the previous form. To be precise i am using windows form as modal forms, and i have started the timer when i am in the 1st form & when i...
21 Mar 2013 by toATwork
From the comments it is clear that the Form is Disposed.Add a breakpoint to theprotected override void Dispose(bool disposing) method of your form and check the call stack who caused the disposal of the Form.
10 Mar 2020 by User 14735579
I am trying to implement heap sort into my code, it should take numbers from the .txt file and sort them using heap sort however, I am getting the error, "Cannot implicitly convert type 'int' to 'int[]'" this is showing up on the line int[] arr...
10 Mar 2020 by Richard Deeming
You're trying to assign a single int variable (value) to an array (arr), which obviously won't work. You're also trying to sort and output the array on each iteration of the first foreach loop, which is almost certainly not what you want. Move...
10 Mar 2020 by Richard MacCutchan
int[] arr = value; The variable value is a single integer, so you cannot store it into an array. You can store it into a single element of an array thus: arr[0] = value; But first you need to create your array given its size: int[] arr =...
15 May 2020 by Member 13160027
I have to update list values with new values daily. the new value is listvalue+newvalue What I have tried: allPayouts = (from p in allPayouts where p.UserID == Paid.UserID select p).ToList().ForEach((p) => { ...
14 May 2020 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email...
15 May 2020 by Richard Deeming
.ToList returns a List[^]. The list's ForEach method[^] executes a specified action for each item in the list. It does not return anything. Therefore, you cannot assign the return value (which doesn't exist) of that method to your variable. ...
29 Mar 2017 by vrushali katkade
i am trying to find running services in my network systems. i am able to get some but for some systems i am getting error"Cannot open Service Control Manager on computer machine name. This operation might require other privileges"ServiceController sc = new...
4 Jul 2011 by Christian Graus
Well, what does the error say ? Your code obviously works, but on some machines, the user does not have the right privileges. Like the message says.
5 Nov 2012 by Narra sreenu
Hi all, In my page have some required field validation controls. these required validations should fire only some button click events. For firing required field validators only in some required button click events, set CausesValidation='True' and for remaining buttons set...
5 Nov 2012 by PramodSawant
Try By Setting buttons property "UseSubmitBehaviour=False"BtnDisplay.UseSubmitBehaviour=False
16 Aug 2011 by nidheeshkayal
Hi Friends,We developed one windows application using VS 2005 with framework 2.0. This application is running perfectly on 32 bit Operating System. Now we need to give support for 64 bit OS. While working with 64 bit Operating System we are getting the below error...
16 Aug 2011 by Espen Harlinn
You are trying to embed a 32-bit ocx in a 64-bit application.Your application will probably run just fine if you force to run as a 32-bit application on a 64-bit OS ... project properties -> build -> Platform Target = x86Best regardsEspen Harlinn
21 Apr 2013 by S.M. Arafat
You can find the solution here:http://support.esri.com/en/knowledgebase/techarticles/detail/33000
9 Aug 2012 by Kamalkant(kk)
"Collection was modified; enumeration operation may not execute " Why this error is coming when execute my below code:This is my Window Form Application in .Net1.I am using a Global class for reading instance message and shown it to a Textbox2.It is executing fine but some time showing...
9 Aug 2012 by Richard MacCutchan
Your question is a bit of a mess so it is difficult to be certain what is happening and when, but I suspect you are adding or removing an item from your list within the foreach loop. That is what the error message is telling you.
17 Jun 2018 by User 12225285
My combo box does not load and keeps showing this error Column 'Item_GenName' does not belong to a table. Here's the code: void loadgeneric() { string constring = "Data Source=D-HOS-MIS2;Initial Catalog=Consignment_db;Persist Security Info=True;User...
17 Jun 2018 by Maciej Los
Take a look at this line: string query = "select distinct convert(varchar,Item_GenName) from ItemMasterlistTable where datalength(Item_GenName) != 0"; This returns something like: (No column name). So, change it as follow: string query = "select distinct convert(varchar,Item_GenName) AS...
2 Jan 2017 by ielsky
Hello Everybody.I have strange situation in my applicaion (MS Outlook Addin).I work with MailItem object in Item.Open event handler.I get Inspector object calling MailItem.GetInspector property.When I try to set handler for Inspector.Close event InvalidComObjectException with message...
1 Feb 2011 by Nish Nishant
One likely cause is that you are accessing a single threaded COM object from different threads. In your case, the event handler may not be running on the thread that created the COM object.
25 May 2016 by Sergey Aseev
You need have strong reference to event.Anything like thisMailItem mailItem;CloseEvent closeEvent;...InspectorEvents_10_Event inspectorEvents = mailItem.GetInspector;closeEvent = inspectorEvents.Close;closeEvent += delegate {.....};
2 Jan 2017 by Jason_Kiscy
hey,Hi, I am facing the same problem it is really difficult to debug it because the test case is not unique. did you find a solution? I really appreciate your help in advance.Here is my mailbox:1424870395@qq.com
12 Apr 2015 by Member 2140700
con = new SqlConnection(cs.DBConn);con.Open();cmd = new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],RTRIM(SubTotal) as [SubTotal],RTRIM(VATPer) as [Vat+ST...
12 Apr 2015 by Richard MacCutchan
cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateFrom.Value.Date.ToShortDateString();Why are you converting the date to a string?
12 Apr 2015 by Member 2140700
the field type in database is nchar(30)...so i am converting it before any process
11 May 2013 by Amogh Natu
Hi, I'm trying out a sample problem on strings wherein I take a string as input and find out the similarity of each of its suffix with itself. For two strings A and B, the similarity of the strings is the length of the longest prefix common to both strings. For example, the similarity of...
11 May 2013 by OriginalGriff
When I run your code with 99,999 byte strings (I cheated and read it from a file) I get "out of system memory" on the first run through GetSuffixes, so start by looking at that - and what do we find?Input string length: 99,999 bytes. "i" is 8,847, so it doesn't get near the end of the...
11 May 2013 by debkumar@codeproject
Instead of storing all sub-strings (suffixes) in list object, calculate the sum of similarities for each suffix. I could not figure out your purpose of calculating the sum of similarity. You can look into KMP failure function if that helps.
16 Apr 2011 by RamyaShivraj
Hello,How do I overcome the "Could not import all the messages" from FxCop tool?I have added few a targets to the FxCop project (Fxcop 1.36 and WPF project) and analyzed.Then a few warning messages have been excluded and saved the fxcop project.Now every time the fxcop project is...
16 Apr 2011 by Anil_Saran
Hi,Kindly follow the below link,As it seems to adjust some project property setting.http://msdn.microsoft.com/en-us/library/bb429341(VS.80).aspx[^]However even after this problem still persist then you can send me the sample on saran.anil@hotmail.com :)Regards,Anil Saran
16 Apr 2011 by #realJSOP
FX-Cop merely provides guidelines. If your code compiles and runs, you don't really have to do anything except fix bugs.
6 Jan 2014 by JayantaChatterjee
Hi all,I create a form which have some function perform on the form_load, at the meantime I want to show a form(like "please wait").I used Background Worker. My code is :-private void QuestionForm_Load(object sender, EventArgs e) { WP = new WorkerProgress();//here...
7 Jan 2014 by OriginalGriff
You cannot access controls exactly from the thread that they were created on: the UI thread.You are trying to access them from your BackgroundWorker, which is a different thread entirely.Either use the Invoke method to access them, or move the code into the UI thread via the...
7 Jan 2014 by Rahul VB
Hello Mam, When ever we start a form based application, the application starts on a single UI thread. Now if i perform some operation using some of its controls. Suppose, on button click, perform some calculation. If the calculation is small its okay, but as the work to be done grows,...
10 Jan 2014 by Rahul VB
Hello Mam, look at the code below: class Class1 { static TableLayoutPanel tlp; public Class1(TableLayoutPanel TLP) { tlp = TLP; } public void doWork(object sender,DoWorkEventArgs e) { ////perform...
11 Jan 2014 by Alan N
Hi Jayanta,I was reading the discussion you were having with OriginalGriff and I wonder if the real problem is the poor performance of Microsoft's TableLayoutPanel. If you are having issues with redraw then enabling double buffering on the control will speed it up. I have found that on .NET...
23 Aug 2014 by junaid2
i have created an application in which i have designed a crystal report and the application has single winform in which there is a crystal report viewer. everything is fine and working but when i try to run that same application on other PC an error occurs saying "crystal report application name...
23 Aug 2014 by OriginalGriff
This isn't a problem we can solve, or even help with that much: we don't have access to your code or to the "other PC".The chances are that when you try to run the app on a different PC, one or more of the assemblies, resources or frameworks that your app requires is not installed, and so it...
19 Dec 2011 by maajanes
"Dim a=b". What type of declaration is this? How can it be used in c#?
19 Dec 2011 by OriginalGriff
It can't be used in c#, it is a VB code line.What it does is declare a new variable a and assign it the value of b. Since VB is not type safe, it doesn't car what type a or b are.C# is type safe. The closest you can get to this are:dynamic a = b;or var a=b;But it is much, much better to...