Friday, March 26, 2010

How to retrieve specific node in an XML file using C#.Net

Here I hv given one of the problem with solution, when I was trying to retrieve specific node of xml file.
Suppose that we have result1.xml file 
<?xml version="1.0" standalone="yes" ?>
<NewDataSet>

  <tblResult>

  <SubmittalId>1</SubmittalId>

  </tblResult>

  <tblResult>

  <Decision>Declined</Decision>

  </tblResult>

  </NewDataSet>

If u want retrieve each node (SubmittalId) & (Decision) separately, we need to use GetElementsByTagName method & XmlAttributeCollection class
private void Button1_click(object sender, EventArgs e)
        {
                        string fdecision = "";
            int subid = 0;
XmlNodeList list = null;
            XmlDocument doc = new XmlDocument();
            doc.Load("pathname"+e.Name);
            list = doc.GetElementsByTagName("Decision");
            for (int i = 0; i < list.Count; i++)
            {
                XmlAttributeCollection xmlattr = list[i].Attributes;
                fdecision = list[i].InnerText;
            }
            XmlNodeList listsubid = doc.GetElementsByTagName("SubmittalId");
            for (int i = 0; i < list.Count; i++)
            {
                XmlAttributeCollection xmlattr1 = listsubid[i].Attributes;
                subid = Convert.ToInt32(listsubid[i].InnerText);
            }
            Console.WriteLine(subid);
            Console.WriteLine(fdecision);
    }

Tuesday, March 16, 2010

Sql Server error - A short note for developer

Yesterday when i was working with VS.Net 2008 I got following error. This happens when I try to make connection string with SQL Server Database.

"Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified"

This error is very strange and i could not resolve it easily. I was working in Windows 7 ultimate. I checked everything but finally got to know the solution. This error happens when u try to connect with sql server 2005. This happened bcoz SQL server did not installed fully. So try to download
1. Microsoft SQL Server System CLR Types
2. Microsoft SQL Server 2008 Management Objects
3. Microsoft SQL Server 2008 Native Client
at
http://www.microsoft.com/downloads/details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en#filelist

I hope this post is useful for every developer!!!