|
There are two possibilities:
- the strings are NOT equal.
- the hashing is different; please read the remarks on MSDN about String.GetHashCode()
|
|
|
|
|
Apparently the string is the cause of my problem.
Using the same web method, I run these codes which return two different results.
Returns true:
public void DoUpload()<br />
{<br />
string data = "This is my string to upload.";<br />
<br />
UploadData(data);<br />
}
Returns false:
public void DoUpload(string cmd, string conn)<br />
{<br />
DataSet ds = new DataSet();<br />
OleDbDataAdapter oAdapter = new OleDbDataAdapter(cmd, conn);<br />
<br />
oAdapter.Fill(ds);<br />
<br />
string data = ds.GetXml();<br />
<br />
UploadData(data);<br />
}
How could that happen? What's the difference between those two string?
I couldn't find any reason why the first code returns true while the other returns false...
I'll make sure they remember my name a hundred years from now!
|
|
|
|
|
Hi,
GetXml() returns a structured text with < and > signs and everything,
it will not return "This is my string to upload."
I am not familiar with databases nor XML, but I think we established your
two strings ARE different. You should have looked at the strings themselves
in the first place !
|
|
|
|
|
Thanks for the reply, Luc Pattyn.
Yes those strings are indeed different, and I'm aware of that.
But the real problem is when I use those strings as a parameter value in UploadData(string data) .
My function works just fine if I use variabel like string data = "Blablabla" or string data = TextBox1.Text or string data = "Bla\nbla\nbla .", they're all return true.
But if I use string data = ds.GetXml() , my function returns false.
Is the string generated with GetXml() has differences from the usual string?
Correct me if I was wrong, but aren't they both string type?
Please help me on this...
WS Code:
[WebMethod]<br />
public int MyWebFunction(string data)<br />
{<br />
int retVal = data.GetHashCode();<br />
<br />
... rest of my code ...<br />
<br />
return retVal;<br />
}
Client-Side Code:
public bool DataUploader(string data)<br />
{<br />
bool retVal;<br />
int hashCode;<br />
<br />
MyWebService ws = new MyWebService();<br />
hashCode = ws.MyWebFunction(data);<br />
<br />
if (hashCode == data.GetHashCode())<br />
{<br />
retVal = true;<br />
}<br />
else<br />
{<br />
retVal = false;<br />
}<br />
<br />
return retVal;<br />
}
I would be very grateful if you could email me the solution (orkaholic@gmail.com).
Again, thanks for your reply Luc.
I'll make sure they remember my name a hundred years from now!
|
|
|
|
|
I am writing a C# application from which I want to play some Shockwave Flash Video (.swf). Now I can use Interop.ShockwaveFlashObjects.dll & AxInterop.ShockwaveFlashObjects.dll to play the video.
Anybody knows what kind of license I need to ditribute these DLLs with my exe?
Thanks
-Tapas
|
|
|
|
|
As these are just the .NET wrappers around the Flash object, I would assume that the only requirement would be that Flash was installed on the client.
|
|
|
|
|
Hi all
I am populating a datagrid with details directly from the database.
now i some new insertion is done in database, the grid should be refreshed..so i am again calling load method to repopulate the grid.Can i refresh the grid with only latest changes that means i dont want to reload the entire data instead i need to load recent data and should be appended to the grid .Is it possible if possible how can i do it
Thanks in advance
Regards
DilipRam
|
|
|
|
|
You probably want to take a look at the BindingSource[^] class. It should handle what you're looking for.
|
|
|
|
|
Thanks for the reply,but since i am loading the data into a datatable and using the datatable count i am adding new row to the grid..so how can i used biniding concept here.can any one help me here
Regards
DilipRam
|
|
|
|
|
The bindingsource does all that for you. When you update the underlying dataset, it updates anything the bindingsource is linked to.
|
|
|
|
|
i m trying to add string's in this collection by calling the Add method of this collection type, but every time i tried to add string in collection of type AutoCompleteStringCollection it gives and invalid cast exception
|
|
|
|
|
You need to make sure that the AutoCompleteSource property is set to AutoCompleteSource.CustomSource . You should be doing something like this:
AutoCompleteStringCollection a = new AutoCompleteStringCollection();
a.Add("test");
a.Add("test 2");
this.textBox1.AutoCompleteCustomSource = a;
this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Greetings!
I am currently trying to implement a small IPC Protocol for 2 of my applications.
Basically, one of them needs to know if the other one is running, and if yes, tell it some orders.
My current setup consists of 3 Main projects:
- IPC: Holds an interface IIPC with a couple of methods that have to be shared.
- MainForm: implements the interface IIPC and is supposed to be shared. Also "starts" the IPC Server.
- PluginDLL: is loaded into a 3rd-party app, and tries to talk to MainForm.
The usual setup consists of the 3rd-party app, which loaded PluginDLL. MainForm is supposed to be started by PluginDLL in case a function is requested.
But its also possible that MainForm is already running, and 3rd-party app is loaded after that. As MainForm exists, its supposed to be used rather than creating a new instance.
First problem there:
I've tried to find out whether MainForm is running by checking if the Channel is already registered:
[MainForm, "serverside"]
class MainForm : MarshalByRefObject, IIPC { ... };<br />
...<br />
Type t = typeof(MainForm);<br />
string ServerChannel = "serverMainForm";<br />
string ObjectName = "mfObject";<br />
...<br />
IpcServerChannel ipcChannel = new IpcServerChannel(ServerChannel);<br />
ChannelServices.RegisterChannel(ipcChannel,true);<br />
RemotingConfiguration.RegisterWellKnownServiceType(t, ObjectName, WellKnownObjectMode.Singleton);
[PluginDLL, "clientside"]
IIPC getIPCObject() {<br />
IpcClientChannel ipcChannel = new IpcClientChannel();<br />
ChannelServices.RegisterChannel(ipcChannel,true);<br />
IIPC ret = (IIPC)Activator.GetObject(typeof(IIPC), "ipc://" + ServerChannel + "/" + ObjectName);<br />
ChannelServices.UnregisterChannel(ipcChannel);<br />
try<br />
{<br />
if (ret.Equals(null)) return null;<br />
}<br />
catch<br />
{<br />
return null;<br />
}<br />
return ret;<br />
}
Unfortunately, GetChannel returned null, even tho I just registered the Channel before.
Enumerating ChannelServices.RegisteredChannels does not return anything inside PluginDLL, inside MainForm it does show the channel I just registered 2 lines before.
For that purpose, I had to use the exception that is thrown when accessing the proxy object with no serverobject behind.
This problem is worked around, but I'd like to know if theres a better way to check if I have an object behind the proxy, or either if the channel exists.
Second problem is the more serious one:
Using above Workaround, I managed to catch the circumstance that MainForm is not running, and run it in this case using System.Diagnostics.Process.Start() . After that, the code above generates a valid proxy - it seems.
But the call to ret.Equals(null) simply hangs, rather than returning false and retrieving the remote object OR failing and throwing an exception - it simply hangs, and wont respond. I also tried to use my own Method/Property/whatever back there instead of Equals, all of them simply hung.
So, what might be the reason for the Proxy object to hang when there is an object?
Or probably, is there any other way to communicate between 2 applications that does not need any additional stuff installed (like MSMQ), that isnt dependant on a port (Remoting with HTTP/TCP; its rather unlikely that a Channel with my programs ID exists already than an arbitrary port that may be used by other programs) or that depends on other lower level code (PostMessage with WM_COPYDATA, needs WinApi and other unmanaged stuff)
Regards, BhaaL
|
|
|
|
|
Hello, I have exactly the same problem. It seems that combination of IPC and Process.Start with RedirectStandardOutput is the problem. And only on Windows XP, it works in all other OS, which is very hard to debug then. Have you found a solution for this? I use RedirectStandardOutput to get message from Console App, that IPC channel is set up. I can certainly wait (say 2 seconds), but it is not a solution, but only a terrible workaround.
|
|
|
|
|
Nope, sorry, I didn't bother with it anymore.
I switched to WCF (using NamedPipes) later on, which is still in use today and works like a charm.
|
|
|
|
|
Hi,
Firstly, I realize I had posted a thread very recently regarding XML serialization, but I can't bump it and this is a different question
I need to serialize a whole data structure, and as it happens I have more than one reference to the same object in different parts of my code, i.e. (trying to think of a simplified example) Imagine a shop that keeps track of each customer's favorite item:
<br />
class Shop<br />
{<br />
Customer customer;<br />
Item[] inventoryList;<br />
<br />
<br />
}<br />
<br />
class Customer<br />
{<br />
Item favoriteItem;<br />
}<br />
When customer is initialised it will have a reference to an item in the inventorylist. As I understand it, the deserializer will generate a new instance of Item for the customer, or I can ignore it, in which case it will be null when I deserialize. Is there a simple solution to get it as a reference to the intended object? I realize that in this case I can just use an index in the array rather than a reference to store the favoriteItem, but this will require major refactoring of my code.
|
|
|
|
|
Hi Friends,
How to Programatically Convert the CSV format to Excel format(.xls) or Simple text format(.txt).
Note: I Have to do this Programatically, Not manully.
Any body have any Idea.
Thanks in advance.
Waiting for your reply.
Thanks & Regards,
Liyakhat.
|
|
|
|
|
CSV to txt is trivial, a csv IS a text file, you'd just be changing what's in it. .xls would require you to interop with Office, obviously.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian,
First of thanks for the reply.
Can you tell me how to convert the CSV file to .xls format(How to interop with office)???
Thanks,
Liyakhat.
|
|
|
|
|
Hi.
In a few words, I have to convert a string retrieved from an Access database to a DateTime object.
I thought I'll use the Convert.ToDateTime() method. But there's the risk that the conversion will fail because the format will not be recognized. I think that this method uses the DateTime format taken from Contol Panel - Language Settings, so this would be tricky if the settings are different on another machine.
What would you do in this case?
Thanks.
|
|
|
|
|
I'd use TryParse to safly see if the conversion is possible. It'll also allow you to specify the format of the date:
System.DateTime.TryParse()[^]
|
|
|
|
|
DateTime.TryParse, but if it fails sometimes, then the other times, it's working because the day is < 13, and you're getting wrong dates.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Is it possible to retrieve the culture information for the machine running the application, and use that specific culture for the conversion?
|
|
|
|
|
I would store it in a culture neutral date format. Let the formatting of the date be taken care of on the client end where it belongs, and store the date using something like YYYY-MM-DD HH:MM:SS
|
|
|
|
|
Yes, but it shouldn't be stored as a string either.
|
|
|
|