|
BillWoodruff wrote: a "bulb as bright" as you Not sure how far this is justified but I'll take it and run
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
In the excel sheet, I have more than 1 lac rows. Am trying to update specific cell and row. It's working and does the update only up to certain row but when I try A106880 row it's saying ' Make sure the object exists and that you spell its name and the path name correctly.'
string sConnection = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=No;IMEX=1""", path);
OleDbConnection _Connection = new OleDbConnection(sConnection);
_Connection.Open();
string cmd = string.Format("Update [{0}$A106880:A106880] set F1 = 12", sheetname);
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(cmd, connection);
if (myCommand != null) myCommand.ExecuteNonQuery();
_Connection.Close();
|
|
|
|
|
Please don't post your question in multiple forums. Choose one and stick to it.
Also posted in Q&A: Oledb excel update is not working[^]
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
By mistake I didn't that. Do you have answer on this?
|
|
|
|
|
example (note: label1 and label2 can have only numbers):
If is label1.Text = 5 and label2.Text = 6
how to make a comparison, something like:
if (label1.Text < label2.Text)
{
MessageBox.Show("some text...",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Please help. Thanks.
|
|
|
|
|
If you are trying to compare numeric values, then parse the strings into an appropriate number format first:
int l1, l2;
if (!(int.TryParse(label1.Text, out l1) && int.TryParse(label2.Text, out l2)))
{
return;
}
if (l1 < l2)
{
...
} If you don't, then string comparisons get a bit weird-seeming, because they base the entire comparison on the first different character pair then encounter in the two strings.
So the sort order isn't what you expect:
"1", "2", "3", ... "9", "10", "11", ... Instead it orders them as
"1", "10", "11", "12", ... "2", "20", "21", ...
Otherwise, just use the String.Compare Method (String, String, StringComparison) (System)[^] to return an integer indicating the result: 0 for "same", -1 for "first is less than second", 1 for "first is greater than second".
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks a lot, doing great. Problem solved.
|
|
|
|
|
You need to convert both strings to numbers first. The following simple test demonstrates that the string "82" is considered less than "9".
string s1 = "82";
string s2 = "9";
int foo = s1.CompareTo(s2);
Console.WriteLine("foo is {0}", foo);
|
|
|
|
|
Hi!
can we update dataset tableadapter without changing from database?
|
|
|
|
|
Uhhhh what? That made no sense at all. What object are you trying to update? The database, the tableupdater, a dataset, ... what? And it what way are you trying to update it?
|
|
|
|
|
of course by turning the read only false
|
|
|
|
|
You're still not making any sense at all.
|
|
|
|
|
how would i go about converting this following code to c# my friend sent it to me but its in c++ and i have no idea what to do with it as i code in c# code
namespace Goat
{
struct IBaseWeapon
{
virtual ~IBaseWeapon() {}
virtual string GetName(void) = 0;
virtual bool AddToCsv(string& strOut) = 0;
};
class Kap40 : public IBaseWeapon
{
public:
Kap40() = default;
virtual string GetName(void)
{
return "kap40";
}
virtual bool AddToCsv(string& strOut)
{
strOut += "xmodel, kap40_viewmodel\n";
strOut += "xmodel, kap40_worldmodel\n";
return true;
}
};
class Ak47 : public IBaseWeapon
{
public:
Ak47() = default;
virtual string GetName(void)
{
return "ak47";
}
virtual bool AddToCsv(string& strOut)
{
strOut += "xmodel, ak47_viewmodel\n";
strOut += "xmodel, ak47_worldmodel\n";
return true;
}
};
class WeaponsMng
{
public:
WeaponsMng() = default;
void AddWeapon(IBaseWeapon* pWeapon)
{
weapons_.push_back(pWeapon);
}
void RemoveWeapon(const string& name)
{
for(auto w : weapons_)
{
const string& curName = w->GetName();
if(curName == name) {
weapons_.remove(w);
}
}
}
string CreateCsc(void)
{
string res;
for(auto w : weapons_)
{
w->AddToCsv(res);
}
return res;
}
private:
std::vector<IBaseWeapon*> weapons_;
};
WeaponsMng mng;
void OnAddKap40_checkbox(bool isChecked)
{
if(isChecked)
mng.AddWeapon(new Kap40());
else
mng.RemoveWeapon("kap40");
}
void OnAddAk47_checkbox(bool isChecked)
{
if(isChecked)
mng.AddWeapon(new ak47());
else
mng.RemoveWeapon("ak47");
}
}
thank you in advance
elfenliedtopfan5.
|
|
|
|
|
Understand exactly what this code is doing and rewrite in C#. You're friend sent it to you so he must have written it correct? He can explain it to you too. Nobody is going to convert it for you.
It would seem there is a ton more going on in the rest of the code that this code interacts with, so a line-by-line conversion is probably not going to do anything for you.
|
|
|
|
|
You can try using the free C++ to C# converter here: [^], but I think the "translation" will only be useful to give you ideas about what the C++ code is doing, and how specific syntaxes map from C++ to C#. And, the output is likely to need considerable "massage."
Until you understand the purpose and usage of the code, you are dancing in the dark.
What I can say about the structure of the code, speaking as a "C/C++ non-native speaker", from a quick glance: ... of course you'll have a NameSpace ....
a. you have an Interface 'IBaseWeapon ... the on-line converter would convert that to an abstract class.
b. you will have (not static) classes, WeaponsMng, Ak47, Kap40
b.1. Ak47 and Kap40 will inherit from 'IBaseWeapon
b.2. WeaponsMng keeps a List of IBaseWeapon
c. you will have some static methods which should be put in a static class
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
I don't think it is productive to use a converter in this case because
C# classes are managed classes while the given C++ class is a native one.
For a Managed C++ (or formally, C++/CLI) class, we should write ref class instead of class - and objects are instantiated in this way:
Object^ obj1 = gcnew Object(); Object^ obj2 = ref new Object();
|
|
|
|
|
Did your friend tell you what the code is supposed to do?
I can tell you it doesn't really "do" much of anything; the "intent" seems to be to provide functionality that will add / remove a weapon from your inventory; but by itself, the code cannot even do that unless it is properly integrated with the "main application" (whatever that may be).
|
|
|
|
|
Hi All,
I am trying to start remote machine process using C# WMI using below code
Objconnection.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", strRemote), Objconnection);
manScope.Connect();
Objconnection.EnablePrivileges = true;
objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Process");
opsObserver = new ManagementOperationObserver();
objSearcher.Scope = manScope;
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(manScope, managementPath, new ObjectGetOptions());
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = "fismqsrvC.exe";
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
uint rtn = System.Convert.ToUInt32(outParams["returnValue"]);
uint processID = System.Convert.ToUInt32(outParams["processId"]);
Console.WriteLine(rtn);
Console.WriteLine(processID);
Above code working correctly for independent processes. But not able to start Process which is Coming Under Particular service. any direction and help appreciated.
Tejendra
|
|
|
|
|
Is this a Windows Service app or a standalone application you're trying to start?
If it's a standalone application, you may be able to start it, but there are some severe restrictions. It can NOT be a user interactive application. This means there can be no user interface if it's a Windows application and for a Console application, it can not wait for user input at all. The user will never see the interface and will never be able to interact with it.
For a Windows Service application, you cannot start it using the Win32_Process WMI class. You have to start it using the Win32_Service class[^].
modified 6-Feb-16 15:28pm.
|
|
|
|
|
Thanks for direction Dave.
I am writing console application which I am planning to schedule on remote server.
I am able to start independent process using my posted code.
But I am not able to start the Process which is coming under Particular service(Means any process which is tightly coupled with Service).
The option I can see here to restart service which will restart related processes. The disadvantage is this activity it will restart my all processes which i don't want to.
let me know your thoughts.
Thanks
|
|
|
|
|
You simply don't have a choice here. Either your app works if started by your Win32_Process code or it doesn't and you have to stop and restart the service.
|
|
|
|
|
yup, Thanks for the Help Dave.
|
|
|
|
|
I have a wrapper class around serial port which looks something like this:
static class HASPCLass
{
private static SerialPort m_port;
private static bool m_initialized;
private static int m_baudRate;
static readonly object _syncObject = new object();
public DoInitialization(int baudRate )
{
lock(_syncObject)
{
if (!m_initialized)
{
Initialize(baudRate);
}
}
}
private Initialize(int baudrate )
{
m_port.open(..);
m_baudRate = baudRate;
m_initialized = true;
}
private Uninitialize()
{
m_port.close();
m_initialized = false;
}
public void Read(byte[] buff)
{
lock(_syncObject)
{
m_port.Read(buff);
}
}
public void Write(byte [] buff)
{
lock(_syncObject)
{
m_port.Write(buff);
}
}
public void Close()
{
lock(_syncObject)
{
if (m_initialized)
{
Uninitialize();
}
}
}
}
I tried making this class thread safe. Someone initializes it - read and writes maybe used from other threads - and in the end calls Close.
Now Imagine I have two additional static methods from other class which do something like this:
public static void function1()
{
HASPClass.Read(...);
HASPClass.Write(...);
}
public static void function2()
{
HASPClass.Read(...);
HASPClass.Write(...);
}
For overall thread safety I also enclosed these functions in locks:
public static void function1()
{
lock(otherlock1)
{
HASPClass.Read(...);
HASPClass.Write(...);
}
}
public static void function2()
{
lock(otherlock1)
{
HASPClass.Read(...);
HASPClass.Write(...);
}
}
Because order in which read and writes are called might be relavant for the serial port/HASP.
My question is: is now my final approach (of using function1 and function2) correct/thread safe? Can I encounter some problems related to threading using function1 and function2?
modified 5-Feb-16 8:08am.
|
|
|
|
|
Locking everything is one way.
Static members are thread-safe as long as they don't access shared resources. The thread creating the serial-class would probably also be the one consuming it; only one consumer per port anyway.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Could you please elaborate your answer, I didn't get you
|
|
|
|