|
For OP's benefit: This reference seems to be pointing out that the minimum date you have specified is the minimum possible SQL date, so there really isn't any reason to be checking for the SQL date > the minimum.
(It would be like checking to ensure an Int32 value was > Int32.MinValue . It will always be true.)
|
|
|
|
|
classy_dog wrote: I am using a linq to sql statement to compare a C# datetime field
There is no way to get an exact match between C# timestamp and SQL Server datetime data type because the precision of the SQL Server data type is 3/1000 of second.
In general one should never attempt to exactly match timestamps across significant boundaries. Instead one should do a timestamp range query.
When doing a range query one should always do an exclusive comparison on one side and an inclusive comparison on the other. If not one allows for the possibility that a value can be missed or duplicated (appearing in two different time ranges.) And example comparison in pseudo code would be the following.
MidnightDateYesterday =....
MidnightDateToday =....
MidnightDateYesterday <= timestamp < MidnightDateToday
|
|
|
|
|
how to save data from listview to database?
|
|
|
|
|
Well you could use data binding or do it manually; but without a bit more information it's difficult to give you a better answer.
Use the best guess
|
|
|
|
|
|
Hi,
I have an xml (Foo.xml)template which is defined as follows:
<Parent:Request xmlns:user="http://xxx.com/">
<Parent:ElemA></Parent:ElemA>
<Parent:ChildNode>
<ElemB></ElemB>
<ElemC></ElemC>
</Parent:ChildNode>
<Parent:ParentName></Parent:ParentName>
</Parent:Request>
In my code, I am able to set the parent elements in the xmltemplate as follows:
public void FooA( MyDomainObject DoM)
{
private readonly XNamespace myNS = "http://ANameSpace.com/";
XElement fooRequestDoc = XElement.Load("Templates/Foo.xml");
XElement ElemA_El = fooRequestDoc.Descendants(myNS + "ElemA").FirstOrDefault();
ElemA_El.SetValue(DoM.ElemA);
}
In this case, if ElemA has a value of "ElementA", then the ElemA_El parameter would be set to this value.
My question is, how do I set a specific Child Note elements such as ElemB or ElemC?
I've tried using "Element" (since I understand it's used to retreive child elements) as follows:
XElement ElemB_El = fooRequestDoc.Element(myNS + "ChildNode");
But it's returning the entire block rather than just ElemB which I seek.
Any help is greatly appreciated!
|
|
|
|
|
public XmlDocument BuildStringToXml(string[,] arrXmlData, string[] FieldName, int RowsCount)
{
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode productsNode = doc.CreateElement("DATA");
doc.AppendChild(productsNode);
for (int i = 0; i < RowsCount; i++)
{
XmlNode productNode = doc.CreateElement("ID");
for (int j = 0; j < FieldName.Length; j++)
{
XmlNode nameNode = doc.CreateElement(FieldName[j]);
nameNode.AppendChild(doc.CreateTextNode(arrXmlData[i, j]));
productNode.AppendChild(nameNode);
}
productsNode.AppendChild(productNode);
}
return doc;
}
hope it helps u
|
|
|
|
|
Thanks,
Here's the solution I accepted on SO:
var nodes = (from node in fooRequestDoc.Descendants(myNS + "ChildNode").Elements() select node).ToList();
|
|
|
|
|
Hi,
When it come to xml serialization and deserialization, I would always use them as objects.
using System;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Text;
namespace Test
{
[Serializable]
[XmlRoot("RootElement")]
public class RootElement
{
[XmlElement]
public int Id { get; set; }
public string Name { get; set; }
public Address Address_1 { get; set; }
public Address Address_2 { get; set; }
}
public class Address
{
[XmlElement]
public string Number {get; set;}
public string Street { get; set; }
public string Town { get; set; }
}
public class Test2
{
Address address_1 = new Address()
{
Number = "123",
Street = "My Road",
Town = "My Home Town"
};
Address address_2 = new Address()
{
Number = "PO BOX 456",
Street = "My Street",
Town = "My Birth Town"
};
public void setXmlValues()
{
RootElement testOut = new RootElement {
Id = 1,
Name = "Customer Name",
Address_1 = address_1,
Address_2 = address_2
};
xml_serialise(testOut);
RootElement testIn = xml_deserialise();
int id = testIn.Id;
string Name = testIn.Name;
string myBirthTown = testIn.Address_2.Town;
}
private void xml_serialise(RootElement test)
{
XmlSerializer ser = new XmlSerializer(typeof(RootElement));
using (TextWriter writer = new StreamWriter("test.xml"))
{
ser.Serialize(writer, test);
}
}
private RootElement xml_deserialise()
{
XmlSerializer ser = new XmlSerializer(typeof(RootElement));
RootElement test;
using (TextReader writer = new StreamReader("test.xml"))
{
test = (RootElement)ser.Deserialize(writer);
}
return test;
}
}
}
I hope this helps.
Regards
Jegan
Think! Don't write a line of code unless you absolutely need to.
|
|
|
|
|
Thanks, I found a simple solution which I posted to the previous response.
|
|
|
|
|
Hello All,
I am converting one of our legacy programs from VB to VS2012 C#.
The problem I am having is that I need to access the inlineshapes of a word document, and I keep throwing an exception: 'Object reference not set to an instance of an object'
Here is my code.
public bool LoadMonthly(ref Document oDoc, int intIndex, DataSet ds, decimal decAvail)
{
bool bStatus = constSUCCESS;
try
{
Microsoft.Office.Interop.Word.InlineShape chartShape = oDoc.InlineShapes[intIndex];
Microsoft.Office.Interop.Graph.Chart oChart;
if (chartShape.OLEFormat.ProgID == "MSGraph.Chart.8")
{
System.Windows.Forms.MessageBox.Show("yep");
}
}
}
Sorry if I missed a paren.
The Document is an active document, I have been updating the tables up until this point.
intIndex is the index for the inlineshape object
The other parameters are of no issue at this point as I cannot get past :
if (chartShape.OLEFormat.ProgID == "MSGraph.Chart.8")
{
System.Windows.Forms.MessageBox.Show("yep");
}
or any other chartShape operation (OleFormat.Edit(), etc....).
Can someone tell me what I am missing here?
This is just a code segment, so please no comments on I'm missing catch blocks or whatever.
Thanks,
jeff
modified 26-Feb-13 17:50pm.
|
|
|
|
|
Object reference not set to an instance of an object is one of the easiest errors to find.
Either chartShape , or chartShape.OLEFormat is null .
In the debugger, set a breakpoint on the if and see what's null that shouldn't be!
|
|
|
|
|
Hi,
it sounds like the "chartShape.OLEFormat.ProgID" has not been initialised in you oDoc reference.
you need to put a break point at the first line of this method, open the local window and check that the oDoc is actually has valid
index to access the "oDoc.InlineShapes[intIndex]", if it has, check that the ProgID has been set to something.
Also you may use the reference equality ".Equals()" instead of operator equality "==" for checking references.
Regards
Jegan
Think! Don't write a line of code unless you absolutely need to.
|
|
|
|
|
chartShape.OLEFormat.ProgID being null will not cause the exception/error described.
It would just cause the if condition to be false .
However, chartShape or chartShape.OLEFormat being null will cause the exception.
|
|
|
|
|
Agree!
Think! Don't write a line of code unless you absolutely need to.
|
|
|
|
|
ok, I have most of this worked out, but do have one problem.
I have a tab delimited text file that I am reading out into a datatable in the code, then pushing that to a stored proc on sql server. That part works but here is the problem.
This file has 15 columns in it. The following code is putting EACH line into the datatable 15 times.....
using (StreamReader file = new StreamReader(@"C:\ProductionLog.txt"))
{
while ((line = file.ReadLine()) != null)
{
char[] delimiters = new char[] { '\t' };
string[] rows = line.Split(delimiters, StringSplitOptions.None);
for (int i = 0; i < rows.Length; i++)
{
dt.Rows.Add(rows);
}
}
file.Close();
}
so I am getting,
BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
15 times( it will do line 2 after it does the 15 and does it 15 times as well), instead of
BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
BUNDLE 01/29/13 01:43 pm 7 5" 7' 64 5 84 1 6 16.96 54.262 9 1 2
BUNDLE 01/29/13 01:44 pm 7 5" 7' 65 5 84 1 6 17.56 33.712 15 4 0
and so on.
Can somebody tell me how much of a dumn** I am being and how to fix this?
Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away.
Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.
|
|
|
|
|
Don't you just want:
dt.Rows.Add(rows);
|
|
|
|
|
|
I've implemented owner drawing when adding items to a listbox. I won't waste time going into it but where I have hit a problem is with colours. Our application will read a column containing an ARGB value for a colour. This value is put into the Color.FromArgb method which returns a Color object which is then applied to the listbox value. If I use exclusively named colours like Color.Red, Color.LimeGreen that sort of thing the listbox is drawn 100% fine. But if the ARGB value isn't a named colour it fails to render anything. It effectively leaves me with white text on a white background.
Has anyone used other than named colours when painting listbox items using OwnerDrawVariable?
As I say, it works perfectly for named colours but the moment I use an ARGB value which isn't a named colour it doesn't actually do anything.
There is a method in the graphics object called GetNearestColor. I tried pumping my ARGB value into it but the Color object it emits is exactly the same as what I sent it. In other words, it doesn't convert a colour that's approximately "slightly like fuschia" for example into Fuschia which is what GetNearestColor is supposed to do. The colour that's in the database is selected by users with the colour picker dialog and they can select any colour or pick one of their own.
Curiously, the same ARGB value works perfectly in a Treeview control.
Any ideas?
"I do not have to forgive my enemies, I have had them all shot." — Ramón Maria Narváez (1800-68).
"I don't need to shoot my enemies, I don't have any." - Me (2012).
|
|
|
|
|
I don't think you'll get an answer to this question unless you reveal the code employed to draw an item and example ARGB values that fail.
PHS241 wrote: This value is put into the Color.FromArgb method which returns a Color object
which is then applied to the listbox value.
That is just too vague.
Alan.
|
|
|
|
|
Well, like Alan said, without seeing your owner-drawing code and an example of a value that fails, the best anyone call tell you is "you screwed up your rendering code".
|
|
|
|
|
Guys,
I found the answer which I'll share. As I said, the treeview displayed the node in the right text colour and background colour. The same ARGB value applied to owner drawing in the listbox did not. The problem was the alpha component. The treeview seems to be more forgiving and accepts alpha values of 0 and 255 as one and the same. The listbox renders alpha values of 0 as fully transparent and 255 as fully opaque which is perhaps the correct result. For a listbox then, I need to force the alpha value to 255. Here is a sample code snippet:
const int anyArgbValueHere = 16744703;
Color argb = Color.FromArgb(anyArgbValueHere);
Color correctedArgb = Color.FromArgb(255, argb.R, argb.G, argb.B); // Same colour but with alpha forced.
When I paint the listbox it now works fine. Obviously, it would be better to have a method that does the conversion as you'd need to handle cases where the colour's IsEmpty property is true.
So, alpha was the problem and not a fault with my owner drawing.
"I do not have to forgive my enemies, I have had them all shot." — Ramón Maria Narváez (1800-68).
"I don't need to shoot my enemies, I don't have any." - Me (2012).
|
|
|
|
|
I would have assumed your drawing code would have handled this situation.
|
|
|
|
|
You mean something like:
using System.Hindsight.Wonderful.Thing
"I do not have to forgive my enemies, I have had them all shot." — Ramón Maria Narváez (1800-68).
"I don't need to shoot my enemies, I don't have any." - Me (2012).
|
|
|
|
|
probably something really dumb but I can not multiple floats and come up with anything but a whole number.
for example
float x = 200031010f;
float y = .86f;
float z = x * y;
I would expect z to be 1722668.6 but it is 1722668
Convert.ToSingle also truncates it to the whole number when converting a double.
what good is a float if multiple just gives whole numbers?
|
|
|
|