h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Get SQL Server Name in C#.net

Today we will discuss about Get SQL Server Name in C#.net
Get SQL Server Name:
 Add Three References in your Project
·         Microsoft .SqlServer.ConnectionInfo
·         Microsoft .SqlServer.management.Sdk.sfc
·         Microsoft .SqlServer.Smo


Declare namespace:


using Microsoft.SqlServer.Management.Smo;

Drag and Drop ComboBox in your form.
DataTable dataTable1 = SmoApplication.EnumAvailableSqlServers(false); cmbServerName1.ValueMember = "Name"; cmbServerName1.DataSource = dataTable1;

Check Password in Vb.net

Today,we will discuss about the Password Checking using regular Expression in VB.net
Here is a Sample code for Password Checking using Regular Expression in VB.Net


Dim reg As Regex
 reg = New Regex("^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$")
     Dim mat As Match = reg.Match(TextBox1.Text)
     If mat.Success = False Then
         MessageBox.Show("Please enter at least one upper case letter, one lower case letter, and one numeric digit.")
         TextBox1.Text = ""
     End If

Use Ternary Operator in Business Layer in C#.Net

      Today we will discuss about the Ternary Operator in Business Layer in C#.Net.
Example for Ternary Operator :
Create a One Class for Business Layer called BLEmp.cs
Copy and paste in the BLEmp.cs File

Private static string _EmpName;
        public static string EmpName
        {
            get { return _EmpName == string.Empty ? "please Enter Name" : _EmpName; }
            set
            { _EmpName = value;   }
        }
 
Drag and Drop TextBox and Button on the form.
Copy and Paste this code in the Button Click Event
 
BLEmp.EmpName = textBox1.Text;
MessageBox.Show(BLEmp.EmpName); 

State Pattern in VB.net

Today we will discuss about the State Pattern in Vb.net.
Description:
    State pattern allows an object to change its behavior depending on the current values of the object. Consider the figure 'State pattern example'. It's an example of a

Box Status operation. If the state of the Box Status is off and you press the switch the BoxStatus will turn off. If the state of BoxStatus is on and you press the switch the Box Status will be off. So

in short depending on the state the behavior changes.
Create a Class file in the Vb.net Project


Enum BoxStatus
      BoxOn = 1
      BoxOff = 2
  End Enum
Public Shared defaultBoxstatus As BoxStatus = BoxStatus.BoxOff
Public Function displayMessage() As String
        If BoxStatus.BoxOn = defaultBoxstatus Then
            Return "Box is on"
        Else
            Return "Box is off"
        End If
End Function
Public Sub Pressswitch()
        If defaultBoxstatus = BoxStatus.BoxOn Then
            defaultBoxstatus = BoxStatus.BoxOff
        Else
            defaultBoxstatus = BoxStatus.BoxOn
End If
End Sub
Dim Clas As New Class1()
  Clas.Pressswitch()
  MessageBox.Show(Clas.displayMessage()) 

Display Crystal Report title -- Programmatically in VB.net

Today , we will see the Display Crystal Report title -- Programmatically in VB.net
Here is a Code:
Create a Text Object in the Design View.
Call this code in the Crystal report viewer Load event.  

Dim cry As CrystalReport1 = New CrystalReport1()
Dim txtHeader As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtHeader") Dim txtAddress1 As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtAddress1") Dim txtAddress2 As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtAddress2") Dim txtAddress3 As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtAddress3") txtHeader.Text = "IBM" txtAddress1.Text = "OMR Road" txtAddress2.Text = "Chennai" Me.CrystalReportViewer1.ReportSource = cry

Query for getting Table name from database

Today , we will discuss about getting Table name from Database
select table_name from INFORMATION_SCHEMA.tables where Table_Type='BASE TABLE'

Enable/Disable date at runtime in DateTime in .Net


Today we will discuss about how to enable and disable date at runtime in DateTime in .Net Drag and Drop DateTimepicker to form. Change in the DatetimePicker:Checked: true
S.NoPro NameModify
1CustomFormatdd/MM/yyyy
2FormatCustom
3ShowCheckBoxTRUE
Run the Application 
unchecked the Check box on the DatetimePicker.
date will disable in the DatetimePicker.

checked  the Check box on the DatetimePicker.
date will enable in the DatetimePicker.

Percentage Validation and Calculation in VB.net

Today , we discussed about Percentage Validation in VB.Net
Dim RegExpression As Regex
Dim RegExpression1 As Regex
RegExpression = New Regex("^((100.00)|([1-9][0-9]|[1-9]|)(\.\d\d))$")
RegExpression1 = New Regex("^((100)|([1-9][0-9]|[1-9]|))$")
If RegExpression.IsMatch(TextBox3.Text) Or RegExpression1.IsMatch(TextBox3.Text) Then
If TextBox3.Text <> "" Then
Dim Dec As Double = CDbl(TextBox1.Text) * CDbl(TextBox3.Text) / 100
Dec = Math.Round(CDbl(Dec), 2, MidpointRounding.ToEven)
TextBox2.Text = Dec.ToString()
Dim result As Double = Math.Round(Dec, 0, MidpointRounding.AwayFromZero)
TextBox4.Text = result.ToString()
End If
Else
MsgBox("Not a match!")
TextBox3.Text = ""
TextBox3.Focus()
End If

XML -- Interview Questions and Answers Part-I




XML -- Interview Questions and Answers:

Part-I

1)       What is XML?
XML is called Extensible Markup Language which is designed to carry or transport and store data. XML tags are not as predefined as HTML, but we can define our own user tags for simplicity. It mainly concentrates on storing of data, not on displaying of data.
2)       What are the features of XML?
Main features of XML are:
• Very easy to learn and implement
• XML files are text files, and no editor is required
• Minimal and a limited number of syntax rules in XML
• It is extensible, and it specifies that structural rules of tags
3)       Which tag is used to find the version of XML and the syntax?
Declaring the XML version is very important for each XML document and platform needs to be specified in which it is running.
<?xml version=”1.1” encoding=”|ISO-8859-1|”?>
4)       What is XML DOM Document?
XML Document object represents the whole XML document, and it is the root of a document tree. It gives access to entire XML document – Nodes and Elements, and it has its own properties.
5)       What is XPath?
XPath is used to find information in an XML document and contains standard functions. XPath is the major element in XSLT, and it is w3c recommendation.
6)       What is an attribute?
An attribute provides more or additional information about an element than otherwise.
Example – <Person name=”Peter”>
Attribute name can be given to an element person.
7)       Can we have empty XML tags?
Yes, we can have empty tags in XML. Empty tags are used to indicate elements that have no textual content. Empty tags can be represented as
<person></person> or • <person/>
8)        What are the advantages of XML DOM Document?
Advantages of XML DOM:
• XML structure is traversable, and it can be randomly accessed by traversing the tree.
• XML structure is modifiable, and values can be added, changed and removed
9)      What are the basic rules while writing XML?
These are the basic rules while writing XML:
• All XML should have a root element
• All tags should be closed
• XML tags are case sensitive
• All tags should be nested properly
• Tag names cannot contain spaces
• Attribute value should appear within quotes
• White space is preserved
10)    What is XML Element?
An XML document contains XML Elements, and it starts from an element’s start tag to end tag. It can contain:
• Other elements within main element
• An Attribute
• text
11)    What is CDATA?
CDATA is unparsed character data that cannot be parsed by the XML parser. Character < and > are illegal in XML elements. CDATA section starts with <![CDATA[“ and end with “]]>”.
12)    How comment can be represented in XML?
Comment can be represented as <!- – comments – -> as like HTML. This comment symbol is applicable for single or multiple lines.
13)    What are XML Namespaces?
XML namespaces are used to avoid element name conflicts, and it can be avoided by using prefix before the name.
14)    What is XML Parser?
XML Parser is used to convert from XML document into an XML DOM object which can be written in JavaScript.
15)    What is XSL?
XSL is a language used with XML for expressing style sheets as like CSS. It describes how to display an XML document for a given type.
16)    Who is responsible for XML?
XML is a recommendation of the W3C – World Wide Web Consortium and the development are supervised by XML working group.
17)    What is an XML Schema?
An XML schema gives the definition of an XML document, and it has following:
• Elements and attributes
• Elements that are child elements
• Order of child elements
• Data types of elements and attributes
18)    What is well formed XML document?
A well-formed XML document must follow the following rules  –
• Every start tag should end with an end tag
• XML tags are case sensitive
• Empty tags are necessary to close with a forward slash
• All tags should be properly nested
19)    Why XML has been used for development?
XML is used for development for following reasons:
• Used for Database driven websites
• Used to store data for e-commerce websites
• Used to transport and store data on internet
• XML is used for database and flat files
• Generate dynamic content by applying different style sheets
20)    What is SGML?
SGML is large and powerful Standard Generalized markup Language which is used to define descriptions of the structure of different types of electronic document.
21)   Can I execute a XML?
No, we cannot execute XML, and it is not a programming language to execute. It is just a markup language to represent the data.
22)    What are the special characters used in XML?
<, > and & are the special characters used in XML. Because these characters are used for making tags.
23)    What software is available for XML?
There are thousands of programs available for XML and updated list will be present in http://xml.coverpages.org.
24)    Whether graphics can be used in XML? If so, How?
Yes, Graphics can be included in XML by using XLink and XPointer specifications. It supports graphic file formats like GIF, JPG, TIFF, PNG, CGM, EPS and SVG.
XLink:
<description
xlink:type=”simple”
xlink:href=”http://show.com/Cinema.gif”
xlink:show=”new”>
</description>
XPointer:
<description
xlink:type=”simple”
xlink:href=”http://show.com/Cinema.gif#Shownumber”
xlink:show=”new”>
</description>
25)    Can I replace HTML with XML?
No, XML is not a replacement of HTML. XML provides an alternative approach to define own set of markup elements, and it is used for processing and storing data.
26)    How can I include conditional statements in XML?
We cannot include conditional statement as like programming language.
<foo if{DB}=”A”>bar</foo>
This can be done by using Document Type Definition(DTD).
<xsl:if test=”@foo=’bar’”>
<xsl:text>Hello, world!</xsl:text>
</xsl:if>
27)   . What are the benefits of XML?
Benefits of XML are
• Simple to read and understand
• XML can be done with a text editor
• Extensibility – No fixed tags
• Self – descriptive
• Can embed multiple data types
28)    What are the disadvantages of XML?
Following are the disadvantages of XML:
• XML will be just a text file if elements and attributes are not defined properly.
• Overlapping markup is not permitted
29)   . What is DTD?
DTD is abbreviated as Document Type Definition and it is defined to build legal building blocks of an XML document. It defines the XML document structure with elements and attributes.
30)    Why XSLT is important for XML?
XSLT is abbreviated as eXtensible Sytlesheet Language Transformation which is used to transform an XML document to HTML before it is displayed to the browser.
31)    What are nested elements in XML?
If one or more elements are nested inside the root element is called nested element. Nesting can be easy to understand and also keeps order in an XML document.
32)    What is XQuery?
XQuery was designed to query XML data which is nothing but SQL for database tables. XQuery is used to fetch the data from the XML file.
33) What is XLink and XPointer?
XLink is the standard way of creating hyperlinks in the XML files. Xpointer which allows those hyperlinks to point to more specific parts of the XML file or document.
33)    Why XML editor is needed instead of Notepad?
XML editors are required to write error free XML documents, and it is used to validate against DTD or schema. Editors are able to check:
• Open and Close Tags
• XML against DTD
• XML against Schema
• Color code on XML Syntax
34)    What is XML Encoding?
XML documents may contain Non-ASCII characters like French and Norwegian characters. XML Encoding is used to avoid errors and XML files have to be saved as Unicode.
35) Which XML is set to be valid XML?
When the XML file is validated against the Document Type Definition(DTD), then it is called valid XML. DTD is nothing but it defines the structure of an XML file.
35)    What is Simple Element?
A simple element contain only text and following are the kinds of Simple Element:
·         No attributes
·         Doesn’t contain other elements
·         It cannot be empty
36)    What is Complex Element?
A complex element contain other elements or attributes and following are kinds of Complex Elements:
·         It has empty elements
·         It contain other elements
·         It contain only text
·         It contain both other elements and text
37)    Is there a way to describe XML data?
Yes, XML uses Document Type Definition (DTD) to describe the data.
38)    What are the three parts of XSL?
XSL consists of three parts:
  • XSLT – Used to transform XML documents
  • XPath - Used for navigating in XML documents
  • XSL-FO - Used for formatting XML documents
39)    What is the correct syntax when we define XML version?
<?xml version=”1.0”/> is the correct declarative syntax used to define XML version.
40)    If XML attribute name itself has double quotes, then how it can be represented?
Attribute name can be represented within single quotes if double quotes are present in the attribute name.
Example<country city=’Texas “US”‘></country>
41)    What are the types of XML Parsers?
There are two types of parsers – Non-Validating and Validating Parsers. Name itself implies Non-Validating will not validate the XML and Validating parser will validate the XML with DTD.
42)    Whether root element is required for XML? If so, how many root elements are required?
Yes, root element is required, and it can have only one root element in each XML.
43)    What is XML Signature?
XML Signature is recommended by W3C, and it acts as a digital signature for XML documents. If the signature is contained outside the document, it is called detached signature. If it contains inside the XML document, then it is called Enveloping signature.


Thanks to GOOGLE.