Simple Alert Message in Javascript

Generate Random Number at runtime

Random class is present under System Name space.
Random random = new Random();
int randomNumber = random.Next();// any random integer value
int anotherRandomNumber = random.Next(5, 100);// this will generate random number greater than 5 and less then 100.
int anotherRandomNumber1 = random.Next(100);// this will generate random number less then 100.

Find last Day of a Month

Dim dt As DateTime = DateTimePicker1.Value
Dim days1 As Integer = Date.DaysInMonth(dt.Year(), dt.Month)
MsgBox("Last Day of " & dt.ToString("MMMM") & " is " & days1) 'Long Format("September")
MsgBox("Last Day of " & dt.ToString("MMM") & " is " & days1) 'Short ("Sep")
MsgBox("Last Day of " & dt.Month.ToString() & " is " & days1) 'Integer Format("9")


Any Doubt Plz post a Comment.

with Regards
santosh

String Manupulation in VB.NET

1.Find Length of String.

Dim StrLength As String = TextBox1.Text
Dim r As Integer =StrLength .Length
MsgBox("Length is " + r.ToString())

2. Find SubString of a String.

Dim r As String = TextBox1.Text 'Textbox1 Lenght should be 7 Charachers
'r = r.Substring(3)
r = r.Substring(4, 3)
MsgBox("Substring of " + r.ToString())

2. Index of SubString.

Dim r As String = "santosh is happy to help u"
r = r.IndexOf("ap")
MsgBox("Index of " + r.ToString())

4. Search SubString inside a String

Dim s1 As String = TextBox1.Text
Dim s2 As String = TextBox2.text
dim r as integer = TextBox1.Text.IndexOf(TextBox2.Text)
If r > 0 Then
MsgBox("Found word, " & r & " characters into the search string.")
Else
MsgBox("Sorry, could not find the search text")
End If


any doubt plz feel free to ask.
With ragards,
santosh

How To Take Backup of DataBase

1. Drag a Button Called(btnBackup).
2.Under btnBackup click you wrie this code.
3. TakeBackUp("DBName", "D:\Backup\NewBackupDBName.bak")
'DBName is DataBase name you want to take Backup.
4.you need to add this two reference.
Microsoft.SqlServer.BatchParser
Microsoft.SqlServer.Replication
5. imports below two packages.
Imports Microsoft.SqlServer.Server
Imports Microsoft.SqlServer.Management.Smo

4. Write a Method called TakeBackUp.
Below is code for TakeBackUp Method

Private Sub TakeBackUp(ByVal BackupDBName As String, ByVal FileNamePath As String)
Try
Dim sqlServerInstance As New Server(New Microsoft.SqlServer.Management.Common.ServerConnection _
(New System.Data.SqlClient.SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=;Data Source=SANTOSH\SQLEXPRESS"))) 'This is only for connection if u give Initial Catalog null it will work
Dim objBackup As New Backup
objBackup.Devices.AddDevice(FileNamePath, DeviceType.File)
objBackup.Database = BackupDBName
objBackup.Action = BackupActionType.Database
objBackup.SqlBackup(sqlServerInstance)
MessageBox.Show("The backup of database " & "'" & BackupDBName & "'" & " completed sccessfully", "Microsoft SQL Server Management Studio", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Sort DataGridView in VB.NET

Dim MyDataView As New DataView
MyDataView = ds.Tables(0).DefaultView
MyDataView.Sort = "SortColumnName"
'SortColumnName is the name of the columnName of DataGridView you want to sort.
DGVFindList.DataSource = MyDataView

Write Birth Day in Existing in XML

1. Add a Windows Form.
2. Drag one TextBox For Entering Name(txtName)
3. Drag one DateTimePicker For Selecting Date of Birth.(dtpBirthDate)
4. Drag a Button(btnWriteXML)

5. Dim XMLPath As String ="F:\XML Files\BirthDay.xml"

6 . Under btnWriteXML Click write this Code.

If txtName.Text = "" Then
MessageBox.Show("Please Enter Name", "BIRTH DAY", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim xmldoc As New Xml.XmlDocument
xmldoc.Load(XMLPath)
Dim node As XmlNode
node = xmldoc.CreateNode(XmlNodeType.Element, "BirthDay", "")
Dim Title As XmlNode = xmldoc.CreateElement("Name")
Dim Title1 As XmlNode = xmldoc.CreateElement("BirthDate", "")
Title.InnerText = txtName.Text
Title1.InnerText = dtpBirthDate.Text
node.AppendChild(Title)
node.AppendChild(Title1)
xmldoc.DocumentElement.AppendChild(node)
xmldoc.Save(XMLPath)
End If

Regards
Santosh

any error please send me request to santosh.mca08@gmail.com

Create and Write BirthDay Details in XML

1. Add a Windows Form.
2. Drag one TextBox For Entering Name(txtName)
3. Drag one DateTimePicker For Selecting Date of Birth.(dtpBirthDate)
4. Drag a Button(btnCreateXML)

5.Dim XMLPath As String ="F:\XML Files\BirthDay.xml"

6. Create a Method Called (createNode)

Private Sub createNode(ByVal Name As String, ByVal BirthDay As String, ByVal writer As XmlTextWriter)
writer.WriteStartElement("BirthDayDetails")
writer.WriteStartElement("Name")
writer.WriteString(Name)
writer.WriteEndElement()
writer.WriteStartElement("BirthDay")
writer.WriteString(BirthDay)
writer.WriteEndElement()
End Sub


7. Under btnCreateXML Click write this Code.

If txtName.Text = "" Then
MessageBox.Show("Please Enter Name", "BIRTH DAY", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim writer As New XmlTextWriter(XMLPath, System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 2
writer.WriteStartElement("BirthDays")
createNode(txtName.Text, dtpBirthDate.Text, writer)
'createNode(2, "Product 2", "2000", writer)
'createNode(3, "Product 3", "3000", writer)
'createNode(4, "Product 4", "4000", writer)
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
End If

with Regards
santosh

any error send request to santosh.mca08@gmail.com

The important classes available under System.XML

XmlReader
XmlWriter
XmlDocument
XMLNode
XMLNodeList
XMLElement
XMLException
XMLTextReader
XMLTextWriter

Retrive Installed Printers from your System

1. Drag a Combobox.
2.Write the following code in Page Load.

For Each Printer As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
ComboBox1.Items.Add(Printer)
Next
ComboBox1.SelectedIndex = o

Add Year in Combobox

Dim i As Integer = System.DateTime.Now.Year
Do While i >= 1950
ComboBox1.Items.Add(i.ToString())
i -= 1
Loop