Wednesday, November 16, 2011

xml DeSerialization xsd.exe

good article
-------

http://blogs.msdn.com/b/yojoshi/archive/2011/05/14/xml-serialization-and-deserialization-entity-classes-with-xsd-exe.aspx

below is simple steps using VS 2010

1) open XML file that you want to deserialize in VS 2010
2) from VS 2010 menu > XML > Create Schema
3) It will create schema in you project save somewhere this .xsd file (in project)
4) go to VS command prompt
5) change path to your .xsd file (where you save above .xsd file)
6) type : xsd myschemafile.xsd /c (must you /c)
7) it will generate myschemafile.cs file in same location
8) type following code

using (FileStream xmlStream = new FileStream(@"C:\book.xml", FileMode.Open))
{
using (XmlReader xmlReader = XmlReader.Create(xmlStream))
{
XmlSerializer serializer = new XmlSerializer(typeof(catalog));
catalog deserializedStudents = serializer.Deserialize(xmlReader) as catalog;
foreach (var b in deserializedStudents.book )
{
Console.WriteLine("author : {0}", b.author);
Console.WriteLine("description : {0}", b.description);
Console.WriteLine("genre : {0}", b.genre);
Console.WriteLine("price : {0}", b.price);
Console.WriteLine("");
}
}
}



generate classes from XSD file

To generate the classes from XSD, run the following on the command line
LinqToXsd.exe /Myschema.xsd

Note: download above exe from codeplex
http://linqtoxsd.codeplex.com/

serialization - Deserialization example

public class MySampleClass
{
//class fields
public string mystring = "Hello World";
public int myint = 1234;
public string[] mystrarray = new string[4];
private int myprivateint = 4321;

//public property
private string _mynameproperty;
public string MyNameProperty
{
get { return _mynameproperty; }
set { _mynameproperty = value; }
}
//constructor
public MySampleClass()
{ }
//public method
public string MyMethod()
{
return _mynameproperty;
}
}


public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
//Serialization exmaple
//serialization is the process of saving class member data into XML
//only public properties and fields can be serialized
MySampleClass objmysampleClass = new MySampleClass();
objmysampleClass.MyNameProperty = "This is Prashant Rathod";
objmysampleClass.mystrarray[0] = "adfsasf";
objmysampleClass.mystrarray[1] = "546345";
objmysampleClass.mystrarray[2] = "uoafas";
objmysampleClass.mystrarray[3] = "34672";

XmlSerializer myxmlserializer = new XmlSerializer(typeof(MySampleClass));
StreamWriter mystreamwriter = new StreamWriter(@"c:\MysampleSerializeXMLfile.xml");
myxmlserializer.Serialize(mystreamwriter, objmysampleClass);
mystreamwriter.Close();
//Deserialization is the reverse process – loading class member data from an XML document
MySampleClass objfromXMLfile = new MySampleClass();
XmlSerializer myserializer = new XmlSerializer(typeof(MySampleClass));
FileStream filestream = new FileStream(@"c:\MysampleSerializeXMLfile.xml", FileMode.Open);
objfromXMLfile = (MySampleClass)myserializer.Deserialize(filestream);

Console.WriteLine(objfromXMLfile.mystring);
Console.WriteLine(objfromXMLfile.MyNameProperty);
Console.WriteLine(objfromXMLfile.myint);
Console.WriteLine(objfromXMLfile.mystrarray);

}
}

Monday, November 14, 2011

reading values from xml datatype in sql database

declare @test xml
DECLARE @ProvPayNoID int
set @test = '
'

SET @ProvPayNoID = @test.value('(/Fields/Field/@Value)[3]', 'int' )
SELECT @ProvPayNoID

declare @providerpayno int

select top 100 convert(xml,ExtraProperties).value('(/Fields/Field/@Value)[1]', 'int' ) as provpayno
from dbm.MedicalClaimsStaging
where BatchId='e5fff885-91bc-40a7-9350-5d176ca2fdfa'


declare @myDoc xml
DECLARE @ProdID int
set @myDoc = '
1 year parts and labor
3 year parts and labor extended maintenance is available
'
SET @ProdID = @myDoc.value('(/Root/ProductDescription/@ProductID)[1]', 'int' )
SELECT @ProdID










'

SET @ProvPayNoID = @test.value('(/Fields/Field/@Value)[3]', 'int' )
SELECT @ProvPayNoID

declare @providerpayno int

select top 100 convert(xml,ExtraProperties).value('(/Fields/Field/@Value)[1]', 'int' ) as provpayno
from mytable



declare @myDoc xml
DECLARE @ProdID int
set @myDoc = '


1 year parts and labor
3 year parts and labor extended maintenance is available


'
SET @ProdID = @myDoc.value('(/Root/ProductDescription/@ProductID)[1]', 'int' )
SELECT @ProdID

Sunday, November 6, 2011

XML to XSD error

Error: Cannot have more than one type of file as input.

because the parameter sequence is not correct.

Parameter should be
nevigate to folder that has xml file

cd c:\xmltoxsdtest
type: XSD myxmlfile.xml
hit enter

create XSD file from XML file

using microsoft XSD.exe tool
1) go to command line (.Net command line)
2) cd path to where your xml file is located (cd c:\myxsdmapping)
3) type "XSD myxmlfile.xml
4) that it -- very simple

Thursday, October 13, 2011

add pssnapin to computer all powershell session - powershell

go to
%systemroot%\System32\WindowsPowerShell\v1.0

2) Create profile.ps1 file
add following

[void][System.Reflection.Assembly]::LoadFile("C:\ProgramFiles\My.Powershell.DLL")
Add-PSSnapin -name "My.Powershell"

3) powershell global config

create powershell.exe.config file
configuration
appSettings
add key="SMTP_SERVER" value="mail.mydomain.com"
add key="email_from" value="HciPowershell@gmail.com"
add key="Working_Path" value="G:\AutoRun\"
add key="healthxhrafromemail" value="DevTeam@hciactive.com"
appSettings
configuration

Monday, October 3, 2011

Tuesday, August 9, 2011

Import XML data into Database


1) Open XML file into Excel (file > Open)
2) It will display Open XML dialog select "Use The XML Source task Pane"
3) Select Ok
4) It will XML schema on left side
5) Drag the XML schema to data area
6) save the Excel workbook as a template
7) open template workbook
8) right click on 1st cell
9) select import XML
10) give the source XML file
11) it will import only matching schema data.

Thursday, March 24, 2011

simple logger code in C#

using System.Diagnostics;
TraceListener logger;
string LogFile = ClientClaimsLoad.Properties.Settings.Default.LogFile;
logger = new TextWriterTraceListener(LogFile);

Trace.Listeners.Add(logger);
Trace.WriteLine("Process started at " + DateTime.Now.ToString());

Trace.Flush();
Trace.Listeners.Remove(logger);
logger = null;
Trace.Write("Process ends at {0}\r\n", DateTime.Now.ToString());

Saturday, February 19, 2011

4 Biggest Lies in Real Estate

CLICK HERE


Some sites to research about to sell or buy house.

1) Zillow
2) CyberHomes
3) Realtor.com
4) RealEstateABC.com


Your mortgage rate site
1) Bankrate.com
2) PriceLine
3) AnnualCreditReport.com

Thursday, February 3, 2011

SSIS Excel connection error

SSIS - excel source error in BIDS - 2008

[Excel Source [528]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.
The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC00F9304.
There may be error messages posted before this with more information on why the AcquireConnection method call failed.


Solution:

go to Projects > Properties > Debugging and change "Run64BitRuntime" to "False"

Monday, January 31, 2011

Thumb Rules for Saving and Retirement

1) do not buy house that cost you more then 2 and 1/2 years of your income
2) save 10% of your income towards your retirement.
3) percentage of portfolio invested in bonds/stock EQUAL TO your AGE
4) never withdraw more then 4% from your retirement savings
5) Stock market would avg. return 10% (long term)
6) emergency fund - 6 month worth of house hold expanses
7) pay high interest credit card bill (debt) first
8) you should have 5 times of your gross salary for unexpected life insurance for family


CLICK HERE


follow this rules

Thursday, January 20, 2011

LINQ join two tables with condition

here is code

var result = from a in dbcontext.dbone
where a.state== "MD" && a.name == "Prashant"
join b in dbcontext.dbtwo
on select new {a.ID,a.DOB,a.GENDER}
equals select new {b.ID,b.DOB,b.GENDER}
select a;

store procedure with return type table in linq

use

SET FMTONLY OFF
in SQL store procedure and following in LINQ code

var MemDetailsOrdered = DataContext.GetOrderedElig(param1,param2,param..).ToList()

other wise it will return default int type