0% found this document useful (0 votes)
20 views

Create INT Primary KEY Nvarchar Nvarchar Insert Into Values Insert Into Values

The document defines a student table in SQL Server with fields for roll number, name, and course. It inserts sample records for two students. It then defines a Windows form application in Visual Basic that exports the student data to an XML file, reads the XML file, and displays it in a list box and datagrid. The application also connects to the SQL Server database, retrieves the student data, exports it to another XML file, and displays it in the datagrid.

Uploaded by

supriya028
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Create INT Primary KEY Nvarchar Nvarchar Insert Into Values Insert Into Values

The document defines a student table in SQL Server with fields for roll number, name, and course. It inserts sample records for two students. It then defines a Windows form application in Visual Basic that exports the student data to an XML file, reads the XML file, and displays it in a list box and datagrid. The application also connects to the SQL Server database, retrieves the student data, exports it to another XML file, and displays it in the datagrid.

Uploaded by

supriya028
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CREATE TABLE [dbo].

[student]
(
[rollno] INT NOT NULL PRIMARY KEY,
[sname] NVARCHAR(50) NULL,
[course] NVARCHAR(50) NULL
)
INSERT INTO [dbo].[student] ([rollno], [sname], [course]) VALUES (1, N'murari', N'MCA')
INSERT INTO [dbo].[student] ([rollno], [sname], [course]) VALUES (2, N'krishna', N'MCA')

Imports System.Xml
Imports System.IO
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim writer As New XmlTextWriter("f:\students.xml", System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 2
writer.WriteStartElement("StudentInfo")
createNode(1, "Pinki", "85", writer)
createNode(2, "chinki", "56", writer)
createNode(3, "pankaj", "89", writer)

createNode(4, "surendra", "95", writer)


writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
End Sub
Private Sub createNode(ByVal sID As String, ByVal sName As String, ByVal smarks As String,
ByVal writer As XmlTextWriter)
writer.WriteStartElement("student")
writer.WriteStartElement("rollno")
writer.WriteString(sID)
writer.WriteEndElement()
writer.WriteStartElement("sname")
writer.WriteString(sName)
writer.WriteEndElement()
writer.WriteStartElement("marks")
writer.WriteString(smarks)
writer.WriteEndElement()
writer.WriteEndElement()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim xmldoc As New XmlDataDocument()
Dim xmlnode As XmlNodeList
Dim i As Integer
Dim str As String = ""
Dim fs As New FileStream("f:\students.xml", FileMode.Open, FileAccess.Read)
xmldoc.Load(fs)
xmlnode = xmldoc.GetElementsByTagName("student")
For i = 0 To xmlnode.Count - 1
xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
str = xmlnode(i).ChildNodes.Item(0).InnerText.Trim() & " " &
xmlnode(i).ChildNodes.Item(1).InnerText.Trim() & " " &
xmlnode(i).ChildNodes.Item(2).InnerText.Trim()
ListBox1.Items.Add(str)
Next
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As
DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim ds As New DataSet
Dim sql As String
connetionString = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=demo1db;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnet
Failover=False"
connection = New SqlConnection(connetionString)
sql = "select * from student"

Try
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
connection.Close()
ds.WriteXml("f:\studentdemo.xml")
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.Show()
MsgBox("Done")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class

You might also like