|
OK, so what's the EXACT contents of location when it fails??
|
|
|
|
|
\\remote comp ip\foldername\filename.docx which is correct
|
|
|
|
|
That's not the EXACT contents. That's just the format you expect it to be in when this code runs.
|
|
|
|
|
Its true that what i have shown is format. But i can't show the actual path. The path i get is as expected
|
|
|
|
|
Oh well, I guess you're on your own now, because the problem seems to be with that path.
|
|
|
|
|
In a C# 2010 desktop application I am using a linq to sql statement to compare a C# datetime field to a sql server 2008 r2 datetime field. By doing this comparison I am getting inconsistent results. Thus I am guessing a C# datetime field is not the same as a sql server 2008 r2 datetime value.
Thus for this comparison to work, I would like to know how to change a C# datetime field to a sql server date time field. I would think I would need to do this conversion prior to comparing the dates.
Thus now you show me code and/or point me to a reference that will show me how to solve this problem?
|
|
|
|
|
The problem is most likely down to the fact that you aren't actually testing what you think you are. The DateTime object has milliseconds associated with it, so if you forget to take those into account, you'll find that you don't get a match.
|
|
|
|
|
hey it is very easy ist in C# hand take string variable instead of taking datetime variable for datetime value..
and at the back end convert it by using convert(datetime,@variable,103) where u r inserting deleting or updating
|
|
|
|
|
He's looking for details on how to do this in Linq though. Perhaps you might want to address this - plus, you shouldn't use a string if what you mean is a date. There is far too much risk, using a string, that you will end up with date conversion issues because of locales.
|
|
|
|
|
I want to compare to see if sql date > minimum date (1/1/1753) and sql date < current today
|
|
|
|
|
Something like this should do it
DateTime minDate = DateTime.ParseExact("1753/01/01, "yyyy/MM/dd", CultureInfo.InvariantCulture,DateTimeStyles.None);
var result = (from p in ctx.SomeTable
where p.MyDate > minDate && p.MyDate < DateTime.Now
select p).ToList();
|
|
|
|
|
I have the following additional questions:
1. The code you have above will let me compare a C# date to a sql server 2008 r2 date,correct? Is there any kind of a conversion needed?
2.Your code listed above will only compare by dates and will not include the time correct?
|
|
|
|
|
classy_dog wrote: 1. The code you have above will let me compare a C# date to a sql server 2008 r2
date,correct? Is there any kind of a conversion needed?
Yes. No.
classy_dog wrote: 2.Your code listed above will only compare by dates and will not include the
time correct?
No. It's DateTime - the time component is included.
|
|
|
|
|
To exclude the time component, you can use DateTime.Today instead of DateTime.Now . Note that this is the beginning of the day so a comparison of other times of the current day will all be greater than that value.
|
|
|
|
|
|
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.
|
|
|
|