Tuesday, 18 December 2012

xmldocument.selectnodes not working

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:thr="http://purl.org/syndication/thread/1.0">

  <title type="html">StackOverflow.com - Questions tagged: c</title>
  <link rel="self" href="http://stackoverflow.com/feeds/tag/c" type="application/atom+xml" />
  <subtitle>Check out the latest from StackOverflow.com</subtitle>
  <updated>2008-08-24T12:25:30Z</updated>
  <id>http://stackoverflow.com/feeds/tag/c</id>
  <creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>


  <entry>
    <id>http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server</id>
    <title type="html">What is the best way to communicate with a SQL server?</title>
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c++" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="sql" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="mysql" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="database" />
    <author>
      <name>Ed</name>
    </author>
    <link rel="alternate" href="http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server" />
    <published>2008-08-22T05:09:04Z</published>
    <updated>2008-08-23T04:52:39Z</updated>
    <summary type="html">&lt;p&gt;I am going to be using c/c++, and would like to know the best way to talk to a MySQL server.  Should I use the library that comes with the server installation?  Are they any good libraries I should consider other than the official one?&lt;/p&gt;</summary>
    <link rel="replies" type="application/atom+xml" href="http://stackoverflow.com/feeds/question/22901/answers" thr:count="2"/>
    <thr:total>2</thr:total>
  </entry>


</feed>



To Get select node

  XmlDocument doc = new XmlDocument();
  XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
  nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
 doc.Load(feed); 
            // successful
  XmlNodeList itemList = doc.DocumentElement.SelectNodes("atom:entry", nsmgr);


xmldocument load ignore dtd -c#


<!DOCTYPE bibdataset PUBLIC
  "-//ES//DTD abstracting and indexing DTD version 5.12//EN//XML"
  "ani512.dtd">



XmlDocument xmlDoc = new XmlDocument();

 xmlDoc.XmlResolver = null;

convert html entity hex to string c#


string Text=Server.HtmlDecode("Paulo Cesa&amp;#x0301;r");

Output:
Paulo Cesár



Monday, 17 December 2012

sql - Count No. of space in a string


select len('this is for test') - len(replace('this is for test', ' ', ''))

Result:
3

Sunday, 16 December 2012

Thursday, 13 December 2012

Open Popup window javascript

function fn_openwindow() {      
            var url= 'popupwindow.aspx';           
            var x = screen.width / 2 - 800 / 2;
            var y = screen.height / 2 - 500 / 2;
            newwindow = window.open(url, 'Report', 'height=500,width=800,resizable=1,left='+x+',top='+y);
            newwindow.focus();
            return false;
        }


Wednesday, 26 September 2012

moving items from one listbox to another c# windows application


        List<string> list = new List<string>();
        List<string> l1 = new List<string>();
        private void Form1_Load(object sender, EventArgs e)
        {
            list.Add("hey");
            list.Add("you");
            list.Add("over");
            list.Add("there");

            listBox1.DataSource = list;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RemoveElements();
        }

        private void RemoveElements()
        {
        
            foreach (var item in listBox1.SelectedItems)
            {
                l1.Add(item.ToString());
                list.Remove(item.ToString());
            }

            listBox1.DataSource = null;
            listBox1.DataSource = list;
            listBox2.DataSource = null;
            listBox2.DataSource = l1;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            RemoveElements();
        }

Friday, 31 August 2012

Tuesday, 28 August 2012

update two tables in one statement in SQL


UPDATE Table1
SET Table1.LastName = 'XXXXXX'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '01'

Handle Errors in Global.asax


Let us see an example of how to use the Global.asax to catch unhandled errors that occur at the application level.
To catch unhandled errors, do the following. Add a Global.asax file (Right click project > Add New Item > Global.asax). In the Application_Error() method, add the following code:

C#
 void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
        Exception objErr = Server.GetLastError().GetBaseException();
        string err = "Error in: " + Request.Url.ToString() +
                          ". Error Message:" + objErr.Message.ToString();
       
    }

VB.NET

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs       
        Dim objErr As Exception = Server.GetLastError().GetBaseException()
        Dim err As String = "Error in: " & Request.Url.ToString() & ". Error Message:"& objErr.Message.ToString()
       
    End Sub

Here we make use of the Application_Error() method to capture the error using the Server.GetLastError().

Friday, 24 August 2012

The underlying connection was closed: The connection was closed unexpectedly.” While returning Data Table from WCF service.


I have changed my operation Contract to return Dataset Instead of Data Table
[OperationContract]
DataSet LoadBatchInformation(string Batch);

Tuesday, 21 August 2012

Fixing innerHTML IE9


        var newdiv = document.createElement("div");
        newdiv.innerHTML = "This is for test" ;
        var container = document.getElementById("container");
        container.appendChild(newdiv);


Friday, 17 August 2012

Code Execution Time using Stop watch


            using System.Diagnostics;
            using System.Threading;        
            ............
    
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            //instead of this there is line of code that you are going to execute
            Thread.Sleep(1000);
            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
            Console.WriteLine(elapsedTime);
            Console.ReadLine();

Monday, 6 August 2012

Sunday, 5 August 2012

Get the value from input control of html


<input name="txt" type="text" value="this is for test" />

string text =Request["txt"];

how to get last record value in sql server without using MAX/TOP clause?


1)SELECT * FROM  tablename WHERE  primarykeyid= IDENT_CURRENT('tablename')

Eg:
SELECT * FROM  tbl_emp WHERE  empid= IDENT_CURRENT('tbl_emp ')

2)
set rowcount 1 
select * from  tbl_emp order by empid desc

SET ROWCOUNT { number | @number_var } 
Causes SQL Server to stop processing the query after the specified number of 
rows are returned.

Enable compatibility mode for IE in C#


<html>
<head>
<meta http-equiv="X-UA-Compatible"content="IE=9;IE=8; IE=7; IE=EDGE" />
<title>My webpage</title>
</head>
<body>
<p>Content goes here.</p>
</body>
</html>

Now it'll try IE9 mode first, IE8, then IE7. You can even set IE=EDGE so it'll use the highest mode possible.

The X-UA-Compatible header is not case sensitive; however, it must appear in the header of the webpage (the HEAD section) before all other elements except for the title element and other meta elements.


Manually
[image[2].png]