c#-2.0

Sum DataTable columns of type string

好久不见. 提交于 2020-01-14 19:51:13
问题 how do i calculate Sum of two rows in datatable which is of type string ? in my case i cannot change column type. i tried these : 1) object objSum; objSum = dt.Compute("Sum(WeightRate)", ""); 2) decimal total = (decimal)dt.Compute("SUM( [WeightRate] )", ""); but no luck... My table : Weightrate No.Ofvehicles 350.50 50 205.00 40 I need result as Weightrate No.Ofvehicle 555.50 90 回答1: The Compute method allows for some rudimentary type conversion: var sum = dt.Compute("Sum(Convert(WeightRate,

C#.Net Windows application - Getting Logged user name in My NT

孤街醉人 提交于 2020-01-14 09:32:29
问题 I need to get the username who logged in particular machine in my LAN. Suggest me a best method to get the user name by passing machine name in C#.net windows application. Also consider the permission. Thanks 回答1: //How about this: string strUserName = WindowsIdentity.GetCurrent().Name; You can then do whatever you want to do with that "strUserName" variable. Please note it also contains the Domain Name if one is present. 回答2: Hi All I got the solution for my question. I used WMI to get the

C#.Net Windows application - Getting Logged user name in My NT

≯℡__Kan透↙ 提交于 2020-01-14 09:32:10
问题 I need to get the username who logged in particular machine in my LAN. Suggest me a best method to get the user name by passing machine name in C#.net windows application. Also consider the permission. Thanks 回答1: //How about this: string strUserName = WindowsIdentity.GetCurrent().Name; You can then do whatever you want to do with that "strUserName" variable. Please note it also contains the Domain Name if one is present. 回答2: Hi All I got the solution for my question. I used WMI to get the

C#.Net Windows application - Getting Logged user name in My NT

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 09:32:04
问题 I need to get the username who logged in particular machine in my LAN. Suggest me a best method to get the user name by passing machine name in C#.net windows application. Also consider the permission. Thanks 回答1: //How about this: string strUserName = WindowsIdentity.GetCurrent().Name; You can then do whatever you want to do with that "strUserName" variable. Please note it also contains the Domain Name if one is present. 回答2: Hi All I got the solution for my question. I used WMI to get the

How can I use a string argument to case a namespace or type?

不羁的心 提交于 2020-01-14 07:24:11
问题 I need to get some JSON output in a .NET 2.0 C# script. The goal is to use one method to output all the JSON feeds I need. All the models have the same id and name properties so I have about 15 namespaces that have the same parts here. In short: since I'm use castle I can call the function like: /public/get_place_tags.castle /public/get_place_types.castle /public/get_place_whichEver.castle Which in castle is calling each method, ie: the get_place_tags(){} but I want to not have to work where

Can we add parameter in datatable.select in c#

老子叫甜甜 提交于 2020-01-12 08:38:50
问题 I like to know is it possible to add parameter in datatable.select(expression).For example string query="Name=@Name"; //dt is comming from database. dt.Select(query); How to add this parameter @Name . I need to compare a value which contains single quote and it gets failed in the above case. Thanks in advance 回答1: You can use String.Format , you need to escape single quotes with two: string query = string.Format("Name='{0}'", name.Replace(@"'", "''")); var rows = dt.Select(query); or, if you

Can we add parameter in datatable.select in c#

℡╲_俬逩灬. 提交于 2020-01-12 08:38:24
问题 I like to know is it possible to add parameter in datatable.select(expression).For example string query="Name=@Name"; //dt is comming from database. dt.Select(query); How to add this parameter @Name . I need to compare a value which contains single quote and it gets failed in the above case. Thanks in advance 回答1: You can use String.Format , you need to escape single quotes with two: string query = string.Format("Name='{0}'", name.Replace(@"'", "''")); var rows = dt.Select(query); or, if you

Method not called when using yield return

僤鯓⒐⒋嵵緔 提交于 2020-01-11 08:26:14
问题 I'm having a little trouble with a method in which I use yield return this doesn't work... public IEnumerable<MyClass> SomeMethod(int aParam) { foreach(DataRow row in GetClassesFromDB(aParam).Rows) { yield return new MyClass((int)row["Id"], (string)row["SomeString"]); } } The above code never runs, when the call is made to this method it just steps over it. However if I change to... public IEnumerable<MyClass> SomeMethod(int aParam) { IList<MyClass> classes = new List<MyClass>(); foreach

Given a bounding box and a line (two points), determine if the line intersects the box

ぐ巨炮叔叔 提交于 2020-01-11 05:17:46
问题 Given a bounding box, with definitions like bounds.min.(x/y/z) , bounds.max.(x/y/z) , and two points in 3D space (expressed as Vector3 objects), how can I determine if the line made by the two points intersects the bounding box? 回答1: There is an implementation in C++ available online here: Line Box Intersection (http://www.3dkingdoms.com/weekly/weekly.php?a=3) Another link, with references (and code) for a lot of intersection tests: http://www.realtimerendering.com/intersections.html If you

Since Modified Header in c#

主宰稳场 提交于 2020-01-06 19:48:51
问题 Am saving Webpages from webbrowser control to the directory like below code. Now i want to check all the webpages daily that is modified or not. if it is modified have to update or else leave it. here i tried something in console application. static void Main(string[] args) { Uri myUri = new Uri("http://www.google.com"); // Create a new 'HttpWebRequest' object with the above 'Uri' object. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); // Create a new 'DateTime'