- Beranda
- Komunitas
- Tech
- Programmer Forum
Bisa minta tolong para master vb.net (vb 2010 & sql server 2005)
TS
portgas.d.lynx
Bisa minta tolong para master vb.net (vb 2010 & sql server 2005)
bisa minta tolong.. ane bikin syntax di vb, buat input data yang nantinya di save ke dalam database dan di tampilkan ke datagrid.. tp ko selalu gagal yea??
bisa minta pencerahanya dimana letak kesalahanya???
dan dengan syntax :
Imports System.Data.SqlClient
Public Class FrmNewData
Dim nmdatabase As String = "Absensi"
Dim strkoneksi As String = " Data Source=.\SQLEXPRESS;AttachDbFilename=;E:\Lynx Propertie'Z\DataBase\Absensi.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;Initial Catalog = Absensi"
Dim koneksiku As SqlConnection
Dim bindingsource As New BindingSource
Sub teskoneksi()
koneksiku = New SqlConnection(strkoneksi)
Try
koneksiku.Open()
koneksiku.Close()
Catch ex As Exception
MsgBox("Koneksi Gagal", MsgBoxStyle.Critical)
End Try
End Sub
Sub tampilkandata()
Dim nmtabel As String = "TbDataSiswa"
Dim strkoneksi As String = "select * From " + nmtabel
Dim dataadapter1 As New SqlDataAdapter(strkoneksi, koneksiku)
Dim datatable1 As New DataTable
dataadapter1.Fill(datatable1)
TbDataSiswaBindingSource.DataSource = datatable1
DataGridView1.DataSource = bindingsource
koneksiku.Close()
End Sub
Private Sub FrmNewData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'AbsensiDataSet.TbPengguna' table. You can move, or remove it, as needed.
Me.TbPenggunaTableAdapter.Fill(Me.AbsensiDataSet.TbPengguna)
'TODO: This line of code loads data into the 'AbsensiDataSet.TbDataSiswa' table. You can move, or remove it, as needed.
Me.TbDataSiswaTableAdapter.Fill(Me.AbsensiDataSet.TbDataSiswa)
teskoneksi()
tampilkandata()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click
Dim SQL As String
SQL = "INSERT Into TbDataSiswa values('" + NisTxt.Text + "','" + NamaTxt.Text + "','" + AlamatTxt.Text + "','" + CbKelamin.Text + "','" + TtlTxt.Text + "','" + Format(DtKalender.Value, "mm/dd,yyyy") + "','" + AgamaTxt.Text + "','" + CbKelas.Text + "','" + TelphoneTxt.Text + "'"
Try
Dim cmd As SqlCommand
cmd = New SqlCommand(SQL, koneksiku)
cmd.Connection = koneksiku
koneksiku.Open()
cmd.ExecuteNonQuery()
koneksiku.Close()
MsgBox("File Has been Registed, Thank's", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("Error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub BtnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRegister.Click
Dim kode As String
Dim nourut As String
Dim strsql As String = "Select * From TbDataSiswa"
Dim da As New SqlDataAdapter(strsql, koneksiku)
Dim dt As New DataTable()
nourut = dt.Rows.Count + 1
If nourut.Length = 1 Then
nourut = "00" & nourut
End If
If nourut.Length = 2 Then
nourut = "0" & nourut
End If
kode = Now.ToString("yy.") & Now.ToString("mm.") & nourut
NisTxt.Text = kode
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
End Class
ko waktu di run, di coba input selalu gagal yea??
mohon bantuanya buat para master??
makasih
bisa minta pencerahanya dimana letak kesalahanya???
dan dengan syntax :
Imports System.Data.SqlClient
Public Class FrmNewData
Dim nmdatabase As String = "Absensi"
Dim strkoneksi As String = " Data Source=.\SQLEXPRESS;AttachDbFilename=;E:\Lynx Propertie'Z\DataBase\Absensi.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;Initial Catalog = Absensi"
Dim koneksiku As SqlConnection
Dim bindingsource As New BindingSource
Sub teskoneksi()
koneksiku = New SqlConnection(strkoneksi)
Try
koneksiku.Open()
koneksiku.Close()
Catch ex As Exception
MsgBox("Koneksi Gagal", MsgBoxStyle.Critical)
End Try
End Sub
Sub tampilkandata()
Dim nmtabel As String = "TbDataSiswa"
Dim strkoneksi As String = "select * From " + nmtabel
Dim dataadapter1 As New SqlDataAdapter(strkoneksi, koneksiku)
Dim datatable1 As New DataTable
dataadapter1.Fill(datatable1)
TbDataSiswaBindingSource.DataSource = datatable1
DataGridView1.DataSource = bindingsource
koneksiku.Close()
End Sub
Private Sub FrmNewData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'AbsensiDataSet.TbPengguna' table. You can move, or remove it, as needed.
Me.TbPenggunaTableAdapter.Fill(Me.AbsensiDataSet.TbPengguna)
'TODO: This line of code loads data into the 'AbsensiDataSet.TbDataSiswa' table. You can move, or remove it, as needed.
Me.TbDataSiswaTableAdapter.Fill(Me.AbsensiDataSet.TbDataSiswa)
teskoneksi()
tampilkandata()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click
Dim SQL As String
SQL = "INSERT Into TbDataSiswa values('" + NisTxt.Text + "','" + NamaTxt.Text + "','" + AlamatTxt.Text + "','" + CbKelamin.Text + "','" + TtlTxt.Text + "','" + Format(DtKalender.Value, "mm/dd,yyyy") + "','" + AgamaTxt.Text + "','" + CbKelas.Text + "','" + TelphoneTxt.Text + "'"
Try
Dim cmd As SqlCommand
cmd = New SqlCommand(SQL, koneksiku)
cmd.Connection = koneksiku
koneksiku.Open()
cmd.ExecuteNonQuery()
koneksiku.Close()
MsgBox("File Has been Registed, Thank's", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("Error", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub BtnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRegister.Click
Dim kode As String
Dim nourut As String
Dim strsql As String = "Select * From TbDataSiswa"
Dim da As New SqlDataAdapter(strsql, koneksiku)
Dim dt As New DataTable()
nourut = dt.Rows.Count + 1
If nourut.Length = 1 Then
nourut = "00" & nourut
End If
If nourut.Length = 2 Then
nourut = "0" & nourut
End If
kode = Now.ToString("yy.") & Now.ToString("mm.") & nourut
NisTxt.Text = kode
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
End Class
ko waktu di run, di coba input selalu gagal yea??
mohon bantuanya buat para master??
makasih
0
1.4K
4
Komentar yang asik ya
Urutan
Terbaru
Terlama
Komentar yang asik ya
Komunitas Pilihan