|
I have a collection like this:
Products
|_Categories
|_Parts
Using Linq-To-SQL, I need to update specific parts in the collection based on the part_number property. I'm not sure of this to write this. Could use some help.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
What have you tried so far? What resources have you looked at?
With Linq2SQL you have an entity object that represents your database table. All you need to do is update the property you want then save the changes within the scope of your DataContext. There are many resources here and elsewhere that cover Linq2Sql and will explain in greater detail
No comment
|
|
|
|
|
hi, I have got some some check boxes which I want to check or uncheck based on values retrieved from database. I tried soething but it did not work. Here is what I tried.
string variable = (string)reader["var"];
if (variable.Equals("1"))
{
checkbox.Checked = true;
}
what can I do? thnx
|
|
|
|
|
If field "var" in the database is always an integer, you could do something like this:-
checkBox.Checked = (int)reader["var"] == 1 ? true : false;
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
or simpler without the ternary operator:
checkBox.Checked = (int)reader["var"] == 1;
|
|
|
|
|
That too
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Well the data type is nchar(20) in sql server, though the data is numeric.
|
|
|
|
|
In that case a direct cast to int will throw an exception. If you require all true values to equal "1" then you could just do this :-
checkBox.Checked = (string)reader["var"] == "1";
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
It is not working. Here is what I tried
checkBox.Checked = ((string)reader["var"] == "1");
|
|
|
|
|
What does it do ? Try using
bool isChecked = (string)reader["var"] == 1;
checkBox.Checked = isChecked;
and putting a breakpoint on checkBox.Checked and see what value isChecked comes up with.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thanks for your patience. This piece of code has worked successfuly
int result = Convert.ToInt32((string)reader["var"]);
if(result == 1)
checkBox.Checked = true
|
|
|
|
|
Hi All,
I am calling a c++ dll from C# application. with out name mangling how can i call c++ function and class from c# application?
Thanks in advance.
G.Paulraj
|
|
|
|
|
You are going to have to use Interop(System.Runtime.Interopservices).Something to the tune of :-
[Dllimport("your dll")]
public static extern void functionName(parameters);
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Hi... thanks for ur quick reply.
in .h file i have declared like
__declspec(dllexport) char* BaseClassFunction();
in .CPP file the definition is like
extern "C" __declspec(dllexport) char* __stdcall ISim::BaseClassFunction()
{
static char* pszCPUType = "derived class function called";
return pszCPUType;
}
from c# i am calling like following...
const String _dllLocation1 = @"D:\Project\Dll.dll";
[DllImport(_dllLocation1)]
static extern String BaseClassFunction();
String Baseclass = BaseClassFunction();
MessageBox.Show(Baseclass.ToString());
the above code is not working...
any help will be appricated..
G.Paulraj
|
|
|
|
|
Paulraj G wrote: the above code is not working.
That is not a very helpful piece of information; exactly what is not working; does the program crash, do you see the wrong results, etc.?
You have defined a DLL function as
extern "C" __declspec(dllexport) char* __stdcall ISim::BaseClassFunction()
and I suspect the ISim:: prefix may be affecting your exported name; you can check with Dependency Walker[^]. Also I am not sure whether a char* returned from C++ will be accepted as a String in C#, you should check the PInvoke rules for marshalling, and also this article[^], and this one[^], by Luc Pattyn[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi - Think it's easier just look at the following code fragment than me attempting to explain this. But basically, Regex.Split isn't splitting the source string way I've expected.
Following example try to split the string at "Timestamp" locations - example "hh:mmPM EST"
<br />
static void TestRegularExpressionSplit()<br />
{<br />
string Src = "467.00 9:32PM EST 467.32 9:33PM EST 468.18 9:34PM EST ";<br />
string SplitExpr = @"([0-9]{1,2}[:]{1}[0-9]{1,2}(PM\sEST){1})";<br />
Regex Expr = new Regex(SplitExpr);<br />
string[] Tokens = Expr.Split(Src);<br />
return;<br />
}<br />
Expected:
467.00
9:32PM EST
467.32
9:33PM EST
468.18
9:34PM EST
Actual:
467.00
9:32PM EST
PM EST
467.32
9:33PM EST
PM EST
468.18
9:34PM EST
PM EST
REF: http://msdn.microsoft.com/en-us/library/ze12yx1d.aspx
dev
|
|
|
|
|
Your MSDN reference says: If capturing parentheses are used in a Regex.Split expression, any captured text is included in the resulting string array.
So, strip those extra capturing parentheses from your regex - you don't need them. You can also simplify it a bit, to something like
string SplitExpr = @"([0-9]{1,2}:[0-9]{1,2}PM\sEST)"; Note I haven't checked this, but it should get you headed in the right direction. You may need to play with the odd \s somewhere to get exactly what you want.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The bracket is causing the issue. This fixed it:
<br />
([0-9]{1,2}[:]{1}[0-9]{1,2}[A|P]{1}M\sEST{1})<br />
dev
|
|
|
|
|
Also, there is a Regex forum (which doesn't get enough traffic).
|
|
|
|
|
I'm not proposing this as a "solution," but more to illustrate a corollary question that this thread brings up, for me.
private string Src = "467.00 9:32PM EST 467.32 9:33PM EST 468.18 9:34PM EST ";
string[] splitOnAry = new string[] { "EST" };
var ListOfValuesAndTimes = Src.Trim().Split(splitOnAry, StringSplitOptions.RemoveEmptyEntries).Select(s => s + "EST").ToList(); Which do you think would be easier to maintain, and, for new programmers (perhaps not deeply versed in RegEx), to understand ? The above code or RegEx ? And, yes, I am ignoring the question of which would be more "performant" under "high load" (given you can compile RegEx in C#).
I admit that doing a Linq iteration just to add "EST" back into the results is ugly, and there is an assumption here, on my part, that CS graduates these days are not coming out of whatever schools with the kind of mastery of RegEx you could expect even ten years ago (a very questionable assumption). And, I'd be curious about to what extent "self-made" programmers ... not coming out of academic CS ... are also as well-versed in RegEx as in days of yore.
Just curious.
thanks, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
Thanks Bill. - I already solved it please see prev post
I posted the reg expr which resolves this issue, seems like RegEx.Split has special handling for "(" and ")" so need be very carefully with that (i.e. with RegEx.Match you wont have the same problem, only with "Split")
Reg expression is such powerfull language (but ... quite hard to master and you can't really expose this via UI to end user as a result of language/expression complexity...)
dev
|
|
|
|
|
devvvy wrote: you can't really expose this via UI to end user Hi,
I just want to make sure you understand that what I am asking in my response to you refers to other developers as being "end-users." And I am speaking to the issue of code maintenance in the context of projects involving complexity and teamwork (not speaking about virtuoso code written by geniuses who will support it to their graves, and perhaps beyond).
I have personally seen cases where complex RegEx's were not fully documented, and then the person who wrote them moved on, or was a temporary consultant, or whatever, and, later, bugs developed requiring modification of the RegEx, and the effort it took on the part of the then available developers to grok the original, and make effective change was a true waste of time.
Perhaps in the ideal world, to get a beginning degree in CS, you'd have to pass a core competency test in RegEx ? I think not. And new tools, like Linq, offer alternatives that are much easier to document, and, imho, maintain. And the times now with amazing desktop CPU horsepower, and relatively vast amounts of memory, allow, I think, for a choice, at times, of high-clarity, highly maintainable, over possibly obscure, but higher-performant, code.
Which is not to say that someone could not document a complex RegEx so well that it would be easy to maintain: I've just, personally, never seen that in the "real-world."
Now if my hypothesis ... that RegEx skills are diminishing among programmers in general over the last ten, twenty, years ... is off-base: well, then 'fugedda about it'
But, I have no bias against RegEx per se, and admire its almost cryptic syntax which is so powerful, just as I once admired certain LISP small functions that, via multiple recursion, did amazing things (the problem being that in order to understand how they did what they did required you to have mental abilities equal to their, often brilliant, creators).
best, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
Hi,
I have a datagridview with 3 columns. In column1 I have a datagridviewcombobox which consists of country. In column2 we have datagridviewcombobox which consists of states. In column I have a datagridviewlinkbutton column when I click on the this link column it will add a new row to the datagrid. This datagridview is on placed on a tabpage of a tab control with the name tab2. When I move to tab1 and come back to tab2 then the datagridviewlinkbutton column is added again i.e., the total number of columns is now 4. But i dont want this to happen i.e., it should only have 3 columns even if i move from tab1 to tab2.
Thanks,
Ajay Chauhan
|
|
|
|
|
I have a product for which I build an MSI with VS setup solution.
Every time I want to deploy my changes the the customer I have to remote desktop to 4 machines, upload my new installer, uninstall the previous version and install the new version (run the MSI).
It's a bit tedious (particularly on 4 machines).
Is there a way I could automate the process (remote login / upload / uninstall / install) ins ome way (with PowerShell for example)?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
You don't have to remote desktop into the machines at all. You do, have to copy the installers out to the machines, then you can either run the install command lines in quiet mode with PSEXEC or open up a CMD prompt with PSEXEC and run the same command line. The usual command line for a quiet unattended install starts with
msiexec /i myinstaller.msi /q
Since you can't see any MSI user interface, you'd have to monitor the msiexec processes using the TaskList command line tool. Something like:
tasklist /FI "imagename eq msiexec.exe"
You'll usually have 3 instances running while an install is in progress. When it's done, it'll drop down to 1 instance.
|
|
|
|
|