Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.SqlClient
- Public Class Form2
- Dim conns As SqlConnection
- Dim da As SqlDataAdapter
- Dim ds As DataSet
- Dim dr As SqlDataReader
- Dim cmd As SqlCommand
- Dim str As String
- Sub koneksisql()
- Try
- str = "Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\INDRA PC\Documents\Visual Studio 2013\Projects\testproject_autoincrement\testproject_autoincrement\Database.mdf"";Integrated Security=True"
- conns = New SqlConnection(str)
- conns.Open()
- MsgBox("connection succesfully")
- Catch ex As Exception
- MsgBox("Koneksi database gagal", MsgBoxStyle.Critical, "error")
- End Try
- End Sub
- Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Call koneksisql()
- TextBox1.Enabled = False
- TextBox2.Focus()
- da = New SqlDataAdapter("select * from user", conns)
- ds = New DataSet
- da.Fill(ds)
- DataGridView1.DataSource = ds.Tables(0)
- DataGridView1.ReadOnly = True
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Call koneksisql()
- Dim simpan As String
- simpan = "insert into user (nama,alamat,phone) values ('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
- cmd = New SqlCommand(simpan, conns)
- cmd.ExecuteNonQuery()
- MsgBox("data berhasil disimpan")
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement