Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.SqlClient
- Imports System.Windows
- Imports System.Xml
- Public Class Form1
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim Username = txtUserName.Text
- Dim phone = txtPhone.Text
- Dim add = txtAddress.Text
- Dim comments = txtComments.Text
- Dim connetionString As String
- Dim connection As SqlConnection
- Dim adapter As SqlDataAdapter
- Dim ds As New DataSet
- Dim sql As String
- Try
- connetionString = "Data Source=(local);Initial Catalog=cand;User ID=test;Password=test"
- connection = New SqlConnection(connetionString)
- connection.Open()
- sql = "Insert Into person values ('" & txtUserName.Text & "','" & txtPhone.Text & "' , '" & txtAddress.Text & "', '" & txtComments.Text & "') "
- adapter = New SqlDataAdapter(sql, connection)
- adapter.Fill(ds)
- Dim insert As New SqlCommand(sql, connection)
- insert.Parameters.AddWithValue(Username, txtUserName.Text)
- insert.Parameters.AddWithValue(phone, txtPhone.Text)
- insert.Parameters.AddWithValue(add, txtAddress.Text)
- insert.Parameters.AddWithValue(comments, txtComments.Text)
- insert.ExecuteNonQuery()
- MsgBox("Successfully Saved")
- Me.Visible = False
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.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=(local);Initial Catalog=cand;User ID=test;Password=test"
- connection = New SqlConnection(connetionString)
- sql = "select * from person"
- Try
- connection.Open()
- adapter = New SqlDataAdapter(sql, connection)
- adapter.Fill(ds)
- connection.Close()
- ds.WriteXml("Person.xml")
- MsgBox("Done")
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement