 |
|
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
cheers, Chris Maunder
The Code Project Co-founder Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 4.34/5 |
|
|
|
 |
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers, Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 3.95/5 |
|
|
|
 |
|
 |
Hi all, I have a datagrid with 4 columns, 1st column is a combobox named "clmOptionNames" where i need to load the values from an combobox named "toolStripComboBox1" who is located outside the datagridview, the rest of the datagrid have values from a webservice and is loaded through the datasource.
Is there anyone who know how to get the content from one combobox and then insert it into a datagridview combobox? the combobox is located at column 0 in the datagridview.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
ah forgot to drop in my code....
frm_Rights frmRights = new frm_Rights(); if (toolStripComboBox1.Text.ToString().Length != 0) { frmRights.label1.Text = toolStripComboBox1.Text.ToString(); frmRights.dataGridView1.Columns[1].HeaderText = "User Name"; frmRights.dataGridView1.Rows.Add("", "user1", "16-08-1971", "16:00:00"); frmRights.dataGridView1.Rows.Add("", "user2", "24-08-1983", "12:00:00"); BindingSource bindCombo = new BindingSource(); bindCombo.DataSource = toolStripComboBox1.Items;
DataGridViewComboBoxColumn datagridCombo = new DataGridViewComboBoxColumn(); datagridCombo.HeaderText = "Hello"; datagridCombo.DataSource = bindCombo; frmRights.dataGridView1.Columns.Add(datagridCombo);
frmRights.ShowDialog(this);
}
The above code works well fine enough - only with the exception that it dont load the content into column 0 but just add a new column onto the datagridview.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
codeproject-template.zip is empty, there is a thread with three posts saying this but no answer in a month, so I just wondered if anyone had a copy and could publish a link to it.
Thankyou
I had to sign up, I felt a bit guilty borrowing code ideas and not giving anything back.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
hello, i discovered this page because of an important need of a c# programm which enables me to plot a mathematical funtion im calculating with my own c# program.
i discovered : 2D Math Curve Presentation for your Project which is exactly what i need: easy and simple.
The problem is that it wont work -due to its date
is somebody able to fix the 2 errors?
Error 1 The call is ambiguous between the following methods or properties: 'System.Math.Floor(decimal)' and 'System.Math.Floor(double)' C:\Documents and Settings\admin\Local Settings\Application Data\Temporary Projects\WindowsApplication2\CurveCalc.cs 291 26 WindowsApplication2
error 2 message loop on a single thread is not a valid operation. Use Form.ShowDialog instead. to this function:
Application.Run(new GraphPlot(funcstr,xs,xe,nump));
waiting for comments
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Normally I would say you should ask in the article's forum but the author doesn't seem to respond to messages there.
THe first problem is because the Math.Abs function returns an int so the Floor method doesn't know which overload to use. The easy way around this is to cast the result to a deciaml or double depending on your needs:redwx=(int)Math.Floor((decimal)(Math.Abs((int)Math.Log10(lox))));
I don't get the second error at all, if I remove the default Program.cs and replace it with the MainFile.cs all works perfectly.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
At first i have to thank you for looking in the code and your effort.
I call the funtion from a class within a public void method and it wont work. I have no idea what [STAThread] in line 8 of the original mainfile does. maybe it's because of that?
P.s: "Normally I would say you should ask in the article's forum but the author doesn't seem to respond to messages there." Thats exactly why i posted here.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I need to alter table programatically in dataset, I need a new column.
Can you please give some example/article about it.
Daniel.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I want to know what's the best way to return value from a fuction in a web service. Presently, a true value is returned if function ran successfully and a false value if not.
So my question is how can i return a value in between them (like true and false value). For instance, a function can get crashed while doing something inside, connecting to the database or couldn't delete a locked file and several other reasons.
I have created functions like these. public bool AddUser(string username) public bool DeleteUser(string userID) public bool GetUser(string userID) public bool DeleteFile(string fileID)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
use try-catch.
public bool MyFunc(string username) { try { ... return true; } catch(Exception) { return false; } }
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I am wondering if you even read my question completely in the message. I am already returning true or false value from a function. But I want to know how could i pass a detailed error message if function crashes rather than a false value.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Return as Int value. Examples:
0 - Success 1 - Invalid User name/Password 2 - Can not connect to database
PS: Returning as Enum can be a little easier PPS: You can create a Struct that has Error Code, and a message. This way you can handle error by its Code and if user needs a info, you could show the message part. There are a lot of ways to achieve this
modified on Friday, November 20, 2009 12:46 PM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Some WinAPI calls handles errors with either int value or has GetLastError(). I have tried MySQL connector.NET and they have tons of errors. In their way they returned a custom Exception. That exception includes ErrorCode and a Message
This is how Microsoft uses: System Error Codes[^]
netJP12L wrote: Is this way big applications deal with complicated applications issues?
Not sure, but this approach I saw in C++ coding style
I Suggest you chose one and stick with it. If you choose returning as Int, Make sure you are documenting every error code and maybe even using constant
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
If you re-throw the exception, then you can provide all the details you might need, and just have it return false. Alternatively, raise an event with the exception details, and know that if you return false you need to check a variable with the reason for failure.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You could also create a custom 'Status' enum that contains a number of different return values, for example...
public enum ReturnStatus{ True, False, Maybe, CriticalError, AcceptableError }
then you function...
public ReturnStatus Func1(string s) { if(s == null) return ReturnStatus.False; if(s == "?") return ReturnStatus.Maybe; return ReturnStatus.True; }
Life goes very fast. Tomorrow, today is already yesterday.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I got an another idea that i am sure you would have thought about it. How about if i were to return an object from every function. This way if the aspx page needs to show what were the exception they can easily show the acutal exception or a custom message. What do you guys think of this idea.
public Object AddUser(string username) { CustomObject obj = null;
try { obj = CustomObject(false,"",,"") } catch(Exception ex) { obj = CustomObject(true,"101",ex,"Database couldn't be started.")
}
return obj; }
public class CustomObject { public CustomObject(bool errorFound, string ErrorID, Exception exception, string CustomErrorMessage) { } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi there, this is - I think - my third post on this subject, which means I was still not able to implement my proxy server. For the people that did not read my other posts, I am trying to use the .NET framework to create a proxy server that intercepts all requests to a certain port and redirects them to an indicated address (indicates by me), appending all the correct credentials (and the purpose of all this thing is to handle the authentication, so that the clients dont need to worry about it). I created a class to implement the server, and I call it like this, inside a thread.
m_prx = new ProxyServer(this); System.Threading.Thread proxythread = new System.Threading.Thread(new ThreadStart(m_prx.Start)); proxythread.Start();
Inside the Start() method, I need to have some sort of listener, waiting for connections; on a first approach, I used a high level implementation that relies on httplistener class:
m_listener.Start(); System.Diagnostics.Debug.WriteLine("Listening socket on port " + m_port); while (true) { HttpListenerContext request = m_listener.GetContext(); ThreadPool.QueueUserWorkItem(ProcessRequest, request);
This relies on the threadPool, which means .NET handles the multithreading at OS level; The function Process Request is, in the essence quite simple: it issues a webrequest (actually httpWebrequest) and appends all the stuff (credentials, headers, etc); then,
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); request.Credentials = AddCache(uri); request.ClientCertificates.Add(SisService.GetClientCertificate());
Then, it grabbs the stream:
buffer = new byte[BUFFER_SIZE]; Stream instream = context.Request.InputStream; int incount = instream.Read(buffer, 0, buffer.Length); while (incount > 0) { request.GetRequestStream().Write(buffer, 0, incount); incount = instream.Read(buffer, 0, buffer.Length); } WebResponse response = request.GetResponse();
and it transfers it into the response:
buffer = new byte[BUFFER_SIZE]; Stream outstream = response.GetResponseStream(); int outcount = outstream.Read(buffer, 0, buffer.Length); while (outcount > 0) { context.Response.OutputStream.Write(buffer, 0, outcount); outcount = outstream.Read(buffer, 0, buffer.Length); } instream.Close(); outstream.Close(); context.Response.OutputStream.Close();
There is some missing code here, but this is pretty much the general idea. It works pretty well, and it is quite fast. However, sometimes (and I believe it is when there are sycnhronous or almost syncrhonous requests from clients) it ends up in this situation (exception):
A first chance exception of type 'System.Net.HttpListenerException' occurred in System.dll An operation was attempted on a nonexistent network connection
I thought it could be a problem with the server, so I tested it with a different server but no luck: same error, when multiple requests were thrown almost at the same time. (I also thought the firewall might be intercepting something here, so I disabled it but it also did not have any influence). So I guess the problem would be with my code...
My perspective was that the httplistener class was not really tackling the multithreading, which I need to have working properly because of the simultaneous requests from clients...
After this, I tried different implementations: - an asynchronous GetContext (beginGetContext) - implementation with real sockets: TCPListener and finally raw sockets;
The implementation with sockets is more or less like this:
TcpListener listener = new TcpListener(IPAddress.Any, m_port); listener.Start();
DoBeginAcceptSocket(listener);
(I also use a ManualResetEvent here to send signals about the threads) Then the callback:
public static void DoBeginAcceptSocket(TcpListener listener) { tcpClientConnected.Reset();
listener.BeginAcceptSocket( new AsyncCallback(ProcessSocket), listener); tcpClientConnected.WaitOne(); }
And the callback "ProcessSocket", is a bit similar to "ProcessRequest", except that is a bit more complex; In the end, since we are not inside a while loop, I need to call DoBeginAcceptSocket again;
This approach, also did not got me out of the problem... now I get a different error, which I think is related to the same issue (except is a different class of exception):
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll An existing connection was forcibly closed by the remote host.
(I also tried a version with the sinchronous "AcceptSocket", with the same results); I am runnning a bit out of ideas here, about what may be the problem... has anyone incurred into this before? I would really appreciate any tips/suggestions on this that could put me into the right direction... I have to add that I am able to catch this error and carry on (even if I have to restart the listener) and in many cases is not a problem (apart from that the user does not see some output cause the requests didnt went trought...) however... not happy about this! Thanks in advance and have a good weekend! Jo
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Why do you read from the outstream???
buffer = new byte[BUFFER_SIZE]; Stream outstream = response.GetResponseStream(); int outcount = outstream.Read(buffer, 0, buffer.Length); while (outcount > 0) { context.Response.OutputStream.Write(buffer, 0, outcount); outcount = outstream.Read(buffer, 0, buffer.Length); }
I think you should read from instream and write to outstream. Maybe that's the problem (I am not sure, as I don't have the full source).
Also, I think the best pattern is: Create a TcpListener. Start it. In a loop, you accept a TcpClient, start a thread to process the client and continues in the loop accepting new requests.
In the thread, you read all and send all.
And, finally, maybe the connection is lost in the middle. This can happen (think about the stop button, for example). So, if the connection is closed, it's ok. Ignore this exception.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Thanks a lot for the reply Paulo!!
Paulo Zemek wrote: I think you should read from instream and write to outstream. Maybe that's the problem (I am not sure, as I don't have the full source).
I think my names are perhaps not very clear, but I am reading from the WebResponse and writing to the HttpListenerContext.Response (which is carried to the callback)
Stream instream = response.GetResponseStream(); Stream outstream = context.Response.OutputStream;
int outcount = instream.Read(buffer, 0, buffer.Length); while (outcount > 0) { outstream.Write(buffer, 0, outcount); outcount = instream.Read(buffer, 0, buffer.Length); } instream.Close(); outstream.Close();
Paulo Zemek wrote: Also, I think the best pattern is: Create a TcpListener. Start it. In a loop, you accept a TcpClient, start a thread to process the client and continues in the loop accepting new requests.
I think I might have tried that approach: do you mean something like this?
TcpListener listener = new TcpListener(IPAddress.Any, m_port); listener.Start(); while (true) { Socket client = listener.AcceptSocket(); ThreadPool.QueueUserWorkItem(ProcessSocket, client); }
(Of course the socket client, could be a TcpListener client, but I'm not sure that makes much difference. This code is also getting into the "Stream closed exception").
Paulo Zemek wrote: And, finally, maybe the connection is lost in the middle. This can happen (think about the stop button, for example). So, if the connection is closed, it's ok. Ignore this exception.
I just dont understand why the connection is closed! Is it getting a timeout for some reason? and why is it only happening when I have multiple requests? (I have to add I am connecting to my server and I know by a fact that no one is accessing it and the connection is not closed, because I tested it) 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Jo,
we've had this conversation before, and I still am convinced using ThreadPool for such things is wrong; the operative word in ThreadPool.QueueUserWorkItem(ProcessRequest, request); is Queue, which means you will typically get fewer threads working for you than there are requests, hence some requests will fail.
So I suggest you forget about TP and add 2 or 3 lines of code to use real Threads instead.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
modified on Friday, November 20, 2009 2:03 PM
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Hi , This is in continuation of my previous post. I am creating a windows application in which i query data from 5-6 tables in sql and display it in excel. My problem is:- I also need to format my excel sheet as follows: the data has different values in 5 columns for the same values in the first 10 columns. I need to show the columns with same data only once and then just populate the columns which have different data for the same value in first 10 columns.
Any help or suggestions are greatly appreciated.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The first thing that comes to my mind is to use a template sheet that you keep filling over and over again. I used the same thing some time ago and it worked
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |