Search Results

Search found 11 results on 1 pages for 'lifeh2o'.

Page 1/1 | 1 

  • How to Avoid Duplicate Key Exception

    - by LifeH2O
    I am using TableAdapter to insert records in table within a loop. foreach(....) { .... .... teamsTableAdapter.Insert(_teamid, _teamname); .... } Where TeamID is the primary key in the table After first run of this loop, Insert throws Duplicate Primary Key found Exception. To handle this, i have done this foreach(....) { .... .... try { _teamsTableAdapter.Insert(_teamid, _teamname); } catch (System.Data.SqlClient.SqlException e) { if (e.Number != 2627) MessageBox.Show(e.Message); } .... .... } But using try catch statement is costly, how to avoid this exception. I am working in VS2010 and INSERT ... ON DUPLICATE KEY UPDATE does not work.

    Read the article

  • When NOT TO USE 'this' keyword?

    - by LifeH2O
    Sorry for asking it again, there are already 3 questions about this keyword. But all of them tell the purpose of 'this'. My question is when not to use 'this' keyword . OR Is it all right to use this keyword always in situation like the code class RssReader { private XmlTextReader _rssReader; private XmlDocument _rssDoc; private XmlNodeList _xn; protected XmlNodeList Item { get { return _xn; } } public int Count { get { return _count; } } public bool FetchFeed(String url) { this._rssReader = new XmlTextReader(url); this._rssDoc = new XmlDocument(); _rssDoc.Load(_rssReader); _xn = _rssDoc.SelectNodes("/rss/channel/item"); _count = _xn.Count; return true; } } here i have not used 'this' with "_xn" and "_count" also not with "_rssDoc.Load(_rssReader);" is it fine? Should i use "this" with all occurrences of class variables within the class?

    Read the article

  • Save XML directly to Database with C#

    - by LifeH2O
    Here is a part of my xml file <teams> <team-profile> <name>Australia</name> <id>1</id> <stats type="Test"> <span>1877-2010</span> <matches>721</matches> <won>339</won> <lost>186</lost> <tied>2</tied> <draw>194</draw> <percentage>47.01</percentage> </stats> <squad> <player id="135" fullname="Shane Warne"/> <player id="136" fullname="Damien Martyn"/> <player id="138" fullname="Michael Clarke"/> </squad> </team-profile> </team> I have read somewhere that there is a way to save this XML directly to database. I am using VS2010. I have created the dataset, for the data i need from this xml. Is there any way to map this XML directly on dataset? Any other idea? I also have to save some other more complex XML files to database. I have tried xsd.exe to create xsd schema for this XML.

    Read the article

  • Fastest way to parse XML files in C#?

    - by LifeH2O
    I have to load many XML files from internet. But for testing with better speed i downloaded all of them (more than 500 files) of the following format. <player-profile> <personal-information> <id>36</id> <fullname>Adam Gilchrist</fullname> <majorteam>Australia</majorteam> <nickname>Gilchrist</nickname> <shortName>A Gilchrist</shortName> <dateofbirth>Nov 14, 1971</dateofbirth> <battingstyle>Left-hand bat</battingstyle> <bowlingstyle>Right-arm offbreak</bowlingstyle> <role>Wicket-Keeper</role> <teams-played-for>Western Australia, New South Wales, ICC World XI, Deccan Chargers, Australia</teams-played-for> <iplteam>Deccan Chargers</iplteam> </personal-information> <batting-statistics> <odi-stats> <matchtype>ODI</matchtype> <matches>287</matches> <innings>279</innings> <notouts>11</notouts> <runsscored>9619</runsscored> <highestscore>172</highestscore> <ballstaken>9922</ballstaken> <sixes>149</sixes> <fours>1000+</fours> <ducks>0</ducks> <fifties>55</fifties> <catches>417</catches> <stumpings>55</stumpings> <hundreds>16</hundreds> <strikerate>96.95</strikerate> <average>35.89</average> </odi-stats> <test-stats> . . . </test-stats> <t20-stats> . . . </t20-stats> <ipl-stats> . . . </ipl-stats> </batting-statistics> <bowling-statistics> <odi-stats> . . . </odi-stats> <test-stats> . . . </test-stats> <t20-stats> . . . </t20-stats> <ipl-stats> . . . </ipl-stats> </bowling-statistics> </player-profile> I am using XmlNodeList list = _document.SelectNodes("/player-profile/batting-statistics/odi-stats"); And then loop this list with foreach as foreach (XmlNode stats in list) { _btMatchType = GetInnerString(stats, "matchtype"); //it returns null string if node not availible . . . . _btAvg = Convert.ToDouble(stats["average"].InnerText); } Even i am loading all files offline, parsing is very slow Is there any good faster way to parse them? Or is it problem with SQL? I am saving all extracted data from XML to database using DataSets, TableAdapters with insert command. I

    Read the article

  • Template function in C# - Return Type?

    - by LifeH2O
    It seems that c# does not support c++ like templates. template <class myType> myType GetMax (myType a, myType b) { return (a>b?a:b); } I want my function to have return type based on its parameters, how can i achieve this in c#? How to use templates in C#

    Read the article

  • Extract some data from a lot of xml files

    - by LifeH2O
    I have cricket player profiles saved in the form of .xml files in a folder. each file has these tags in it <playerid>547</playerid> <majorteam>England</majorteam> <playername>Don</playername> the playerid is same as in .xml (each file is of different size,1kb to 5kb). These are about 500 files. What i need is to extract the playername, majorteam, and playerid from all these files to a list. I will convert that list to XML later. If you know how can i do it directly to XML i will be very thankful.

    Read the article

  • null reference expction in the code

    - by LifeH2O
    I am getting NullReferenceException error on "_attr.Append(xmlNode.Attributes["name"]);". namespace SMAS { class Profiles { private XmlTextReader _profReader; private XmlDocument _profDoc; private const string Url = "http://localhost/teamprofiles.xml"; private const string XPath = "/teams/team-profile"; public XmlNodeList Teams{ get; private set; } private XmlAttributeCollection _attr; public ArrayList Team { get; private set; } public void GetTeams() { _profReader = new XmlTextReader(Url); _profDoc = new XmlDocument(); _profDoc.Load(_profReader); Teams = _profDoc.SelectNodes(XPath); foreach (XmlNode xmlNode in Teams) { _attr.Append(xmlNode.Attributes["name"]); } } } } the teamprofiles.xml file looks like <teams> <team-profile name="Australia"> <stats type="Test"> <span>1877-2010</span> <matches>721</matches> <won>339</won> <lost>186</lost> <tied>2</tied> <draw>194</draw> <percentage>47.01</percentage> </stats> <stats type="Twenty20"> <span>2005-2010</span> <matches>32</matches> <won>18</won> <lost>12</lost> <tied>1</tied> <draw>1</draw> <percentage>59.67</percentage> </stats> </team-profile> <team-profile name="Bangladesh"> <stats type="Test"> <span>2000-2010</span> <matches>66</matches> <won>3</won> <lost>57</lost> <tied>0</tied> <draw>6</draw> <percentage>4.54</percentage> </stats> </team-profile> </teams> I am trying to extract names of all teams in an ArrayList. Then i'll extract all stats of all teams and display them in my application. Can you please help me about that null reference exception?

    Read the article

  • How to use Unique Composite Key

    - by LifeH2O
    I have a table Item(ItemName*, ItemSize*, Price, Notes) I was making composite key of (ItemName,ItemSize) to uniquely identify item. And now after reading some answers on stackoverflow suggesting the use of UNIQUE i revised it as Item(ItemID*, ItemName, ItemSize, Price, Notes) But How to apply UNIQUE constraint on ItemName and ItemSize please correct if there is something wrong in question

    Read the article

  • Program LED with just USB port

    - by LifeH2O
    I want to control LED with C# using only USB port. I don't want to attach any other device with USB. I just want to attach LED directly to USB port pins and program it (blink etc). How can i do that? I am new to hardware programming and it will be my first program. EDIT: I can do it already (blink LED) using printer port by attaching one led pin to data pin and other to ground. How can i do the same with USB port? My motherboard does not have a printer port. USB is the only option.

    Read the article

  • null reference exception in the code

    - by LifeH2O
    I am getting NullReferenceException error on "_attr.Append(xmlNode.Attributes["name"]);". namespace SMAS { class Profiles { private XmlTextReader _profReader; private XmlDocument _profDoc; private const string Url = "http://localhost/teamprofiles.xml"; private const string XPath = "/teams/team-profile"; public XmlNodeList Teams{ get; private set; } private XmlAttributeCollection _attr; public ArrayList Team { get; private set; } public void GetTeams() { _profReader = new XmlTextReader(Url); _profDoc = new XmlDocument(); _profDoc.Load(_profReader); Teams = _profDoc.SelectNodes(XPath); foreach (XmlNode xmlNode in Teams) { _attr.Append(xmlNode.Attributes["name"]); } } } } the teamprofiles.xml file looks like <teams> <team-profile name="Australia"> <stats type="Test"> <span>1877-2010</span> <matches>721</matches> <won>339</won> <lost>186</lost> <tied>2</tied> <draw>194</draw> <percentage>47.01</percentage> </stats> <stats type="Twenty20"> <span>2005-2010</span> <matches>32</matches> <won>18</won> <lost>12</lost> <tied>1</tied> <draw>1</draw> <percentage>59.67</percentage> </stats> </team-profile> <team-profile name="Bangladesh"> <stats type="Test"> <span>2000-2010</span> <matches>66</matches> <won>3</won> <lost>57</lost> <tied>0</tied> <draw>6</draw> <percentage>4.54</percentage> </stats> </team-profile> </teams> I am trying to extract names of all teams in an ArrayList. Then i'll extract all stats of all teams and display them in my application. Can you please help me about that null reference exception?

    Read the article

1