|
You don't query the connection, you query the database it is connected to, and that depends on the database. In SQL Server; SELECT * FROM sys.Tables
only two letters away from being an asset
|
|
|
|
|
Have a c app that may be converted to c#, but I am having a problem with this:
From OTHER apps written in C++, a buffer is written to the socket (which will be read by the future C# app) from variables based on several different TYPEDEFs, for example:
typedef SAMPLE1
{
int32 msg_id;
char status[15];
float value;
};
...
...
SAMPLE1* samp;
samp->msg_id = 100;
strcpy(samp->status, "NOTYPEDEF?");
samp->value = 120.123f;
send(samp, sizeof(SAMPLE1));
...
...
In the soon-to-be-replace C app, I just read the socket buffer and based on the msg_id, cast it to the appropriate TYPEDEF, functionaliy which for some silly reason Billy G. decided C# did not need.
Does anyone know of a way for C# to parse thru the socket data, where the sending apps cannot be modified to change how the data is sent?
Unless I'm missing something, serialization does not seem to be an option because the data read will not hold any object data.
|
|
|
|
|
Hi,
I have some pointers for you:
1.
this is not a typedef, it is a struct.
C# knows about structs.
2.
in .NET an array is a managed object, hence the struct would contain an int, a reference to some Unicode characters, and a float. Not what the other side is thinking of.
3.
if the string really is 15 8-bit characters, I suggest you use a byte array, not a char array. That solves the width problem. It also needs a conversion, as offered by Encoding.GetBytes and Encoding.GetString; you need the proper encoding for this to handle your top half of the charset correctly; in the Western world Encoding(1252) is the prime candidate.
4.
now you must make sure the array content, not its reference, sit inside the struct.
that takes [StructLayout(LayoutKind.Sequential)] before the struct
and [MarshalAs(UnmanagedType.ByValArray, SizeConst=15)] before the byte[]
5.
then there is the issue of padding, here the question is: does or doesn't the C++ side insert a dummy byte to get the float "naturally aligned". I don't know, it depends on compiler defaults and possible presence of explicit pragma's. Easiest would be to look at the data, and/or try both. A simple way to force padding is by inserting a byte as in byte dummy; ; there isn't a simple way to avoid padding. I tend to use
[FieldOffset(x)] in front of every struct member, where x is the byte offset you have to calculate correctly.
So, this should get you started (for a long while maybe).
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
modified on Thursday, October 15, 2009 4:56 PM
|
|
|
|
|
I am reading this excel file and searching for the word "Yellow" Everything is fine until I reach a type double. How do I handle this. My code is below.
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
Excel.Range range ;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Opentest", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(8); // Opens the 8th tab in workbook
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
System.Convert.ToString(xlWorkBook);
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;
if (str == "Yellow" )
MessageBox.Show(str);
}
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
MessageBox.Show("Unable to release the Object " + ex.ToString());
}
In other words how can I convert his whole spreadsheet to type string. I am new to this thanks.
|
|
|
|
|
Hi,
I've never done Excel programming, however I expect the problem is in str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ; as this statement assumes Value2 can be cast to string.
BTW: You should have provided a try-catch, look at the line number in the exception output, and use your IDE to look at the offending line.
Here are three ideas (in decreasing preference):
1.
str = (range.Cells[rCnt, cCnt] as Excel.Range).Value2 as string;
this results in str being the cell content if it was a string, and null otherwise.
2.
str =(range.Cells[rCnt, cCnt] as Excel.Range).Value2.ToString() ;
however this would fail if Value2 were null
3.
you could add a try-catch inside the inner loop, and skip the failing cells
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi all,
Weird problem: When I set focus to a scrolled control, it resets the scroll position to (0, 0).
This happens with three different methods for setting focus: Focus (), Select (), and setting the parent's ActiveControl.
Resetting the correct scroll position after setting focus doesn't work: The scrollbars disappear!
MSDN doesn't even mention this phenomenon. A solution is proposed here http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/437437c8-9548-4e68-8f17-356f848f379d[^] but has no effect for me.
Any suggestions how I can set focus to a control without screwing up the scroll position? Thanks!
|
|
|
|
|
I presume this control has items such as ListViewItem. I hope you do not force it to refresh any items in it
|
|
|
|
|
That solution works for me, I really appreciate you post that link.
Diffy
|
|
|
|
|
I have an app that needs to read in excel files. However the users keep leaving them open, so I want to
save changes and close them. I have no read experience in WinAPI in C#. Could someone help?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
simply kill the Excel process, or shutdown the system, or disconnect the power cord, each time this happens, and until the users have learned it doesn't make any sense to enter data and not save it.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Well, golly gee, you DO have good ideas.
Everything makes sense in someone's mind
|
|
|
|
|
yust make sure you detect excel is opend and if it is, promp it to users to save changes and close
|
|
|
|
|
Yes, but HOW??
I'm looking for the code to automate this.
Everything makes sense in someone's mind
|
|
|
|
|
|
i developed two websites in asp.net (c#)
they should send info to each other
please some one help me in sample code about that
|
|
|
|
|
Considering there are innerable ways to do this, it's impossible to tell you what you need to know. You haven't provided ANY details at all on what kinds of app these are, what the data is you intend to share, where it's stored, if they share a common data store of some kind, if the apps are on the same server or on different servers, if you need real-time communication between the two, if the transfer needs to be ecapsulated in a transaction of some kind, ... on and on and on.
Basically, noone can answer your question as asked.
|
|
|
|
|
thank you for your reply
i really think about HTTP request
assume that first sever collect the information from table in database that he (the first server) owns rearrange it and send it to the second server the second will receive that date and update its database that exist on it (owned by second) upon to that data
data could be sting , text , int ...
|
|
|
|
|
Check into writing a web service and installing it on the second server.
|
|
|
|
|
|
Hello,
How we can define a table of array list in an function, i try for :
public ArrayList[] stringArray = new ArrayList[2];
public static ArrayList Tbl = new ArrayList();
public static ArrayList Tbl2 = new ArrayList();
public stringArray verification(string path, string path_save)
I would define a type stringArray.
thank you verry mutch.
|
|
|
|
|
I was going to say "I don't understand what you want", but on second thoughts:
Are you trying to return an ArrayList as the result of the verification method? if so, then decalre it as
public ArrayList[] verification(string path, string path_save) and it should work.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
How we can define a array of array list? thank you verry mutch.
|
|
|
|
|
abbd wrote: How we can define a array of array list?
how do you define an array of int?
how do you define an array of Object?
why do you think it would be any different?
And why are you using old ArrayList rather than generic List<T>?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Are tere a difference between List<t> and ArrayList, i would define an array of arraylist of string. thank you verry mutch.
|
|
|
|
|
As i saw in msdn, ArrayList holds only String Objects, while List can use any type including custom class, struct and so on
|
|
|
|
|