Imports System.Data.SqlClient
Imports System.IO
Public Class Form7
Dim cmd As New SqlCommand
Dim adp As New SqlDataAdapter
Dim ds As New DataSet
Dim p As Integer
Dim cmb As New SqlCommandBuilder
Dim cnt As Integer
'========================================
Private Sub showRec()
Dim row As DataRow
row = ds.Tables(0).Rows(cnt)
TextBox1.Text = row(0)
TextBox2.Text = row(1)
TextBox3.Text = row(2)
DateTimePicker1.Value = row(3)
If row(4) = "M" Then
Rdb1.Checked = True
Else
Rdb1.Checked = False
End If
If row(4) = "F" Then
Rdb2.Checked = True
Else
Rdb2.Checked = False
End If
ComboBox1.Text = row(5)
If row(6) = "1" Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
If row(7) = "1" Then
CheckBox2.Checked = True
Else
CheckBox2.Checked = False
End If
If row(8) = "1" Then
CheckBox3.Checked = True
Else
CheckBox3.Checked = False
End If
End Sub
'=====================================================
Private Sub DataGridView1_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
p = e.RowIndex
TextBox1.Text = DataGridView1.Rows(p).Cells(0).Value
TextBox2.Text = DataGridView1.Rows(p).Cells(1).Value
TextBox3.Text = DataGridView1.Rows(p).Cells(2).Value
DateTimePicker1.Value = DataGridView1.Rows(p).Cells(3).Value
If (DataGridView1.Rows(p).Cells(4).Value = "M") Then
Rdb1.Checked = True
Else
Rdb1.Checked = False
End If
If (DataGridView1.Rows(p).Cells(4).Value = "F") Then
Rdb2.Checked = True
Else
Rdb2.Checked = False
End If
ComboBox1.Text = DataGridView1.Rows(p).Cells(5).Value
If (DataGridView1.Rows(p).Cells(6).Value = "1") Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
If (DataGridView1.Rows(p).Cells(7).Value = "1") Then
CheckBox2.Checked = True
Else
CheckBox2.Checked = False
End If
If (DataGridView1.Rows(p).Cells(8).Value = "1") Then
CheckBox3.Checked = True
Else
CheckBox3.Checked = False
End If
End Sub
'=======================================================
Private Sub clearedata()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
Rdb1.Checked = False
Rdb2.Checked = False
ComboBox1.Text = "--Select--"
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
End Sub
'=======================================================
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Module1.Connect()
adp = New SqlDataAdapter("select * from Emp order by Eno", Module1.cn)
adp.Fill(ds)
cmb = New SqlCommandBuilder(adp)
DataGridView1.DataSource = ds.Tables(0)
clearedata()
End Sub
'=====================================================
Private Sub BtnAdd_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
Panel1.Enabled = True
clearedata()
cmd = New SqlCommand("Select max(Eno) from Emp", Module1.cn)
Dim cnt
cnt = cmd.ExecuteScalar()
If cnt Is DBNull.Value Then
cnt = 1
Else
cnt = cnt + 1
End If
TextBox1.Text = cnt
TextBox1.ReadOnly = True
TextBox2.Focus()
'Panel3.Visible = True
Panel2.Visible = False
End Sub
'==========================================================
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
'cmd = New SqlCommand("Insert into Emp values (@p1,@P2,@p3,@p4,@p5,@p6,@p7,@p8,@p9)", Module1.cn)
'cmd.Parameters.AddWithValue("@p1", TextBox1.Text)
'cmd.Parameters.AddWithValue("@p2", TextBox2.Text)
'cmd.Parameters.AddWithValue("@p3", TextBox3.Text)
'cmd.Parameters.AddWithValue("@p4", DateTimePicker1.Value)
'If Rdb1.Checked = True Then
' cmd.Parameters.AddWithValue("@p5", "M")
'Else
' cmd.Parameters.AddWithValue("@p5", "F")
'End If
'cmd.Parameters.AddWithValue("@p6", ComboBox1.Text)
'If (CheckBox1.Checked = True) Then
' cmd.Parameters.AddWithValue("@p7", "1")
'Else
' cmd.Parameters.AddWithValue("@p7", "0")
'End If
'If (CheckBox2.Checked = True) Then
' cmd.Parameters.AddWithValue("@p8", "1")
'Else
' cmd.Parameters.AddWithValue("@p8", "0")
'End If
'If (CheckBox3.Checked = True) Then
' cmd.Parameters.AddWithValue("@p9", "1")
'Else
' cmd.Parameters.AddWithValue("@p9", "0")
'End If
'cmd.ExecuteNonQuery()
'MsgBox("Saved Data..")
'Panel1.Enabled = False
'=================SecondMethod============================
Dim row As DataRow
row = ds.Tables(0).NewRow
row(0) = TextBox1.Text
row(1) = TextBox2.Text
row(2) = TextBox3.Text
row(3) = DateTimePicker1.Value
If Rdb1.Checked = True Then
row(4) = "M"
Else
row(4) = "F"
End If
row(5) = ComboBox1.Text
If (CheckBox1.Checked = True) Then
row(6) = "1"
Else
row(6) = "0"
End If
If (CheckBox2.Checked = True) Then
row(7) = "1"
Else
row(7) = "0"
End If
If (CheckBox3.Checked = True) Then
row(8) = "1"
Else
row(8) = "0"
End If
If (CheckedListBox1.CheckOnClick = True) Then
row(6) = "1"
Else
row(6) = "0"
End If
ds.Tables(0).Rows.Add(row)
adp.Update(ds)
MsgBox("Data inserted")
clearedata()
'For Each item In CheckedListBox1.CheckedItems
' row(6) = item.ToString & " "
'Next
End Sub
'==================================================
Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
cmd = New SqlCommand("Update Emp set Name=@P2,Salary=@p3,Jdate=@p4,Gender=@p5,City=@p6,Vbnet=@p7,php=@p8,Aspnet=@p9 where Eno=@p1", Module1.cn)
cmd.Parameters.AddWithValue("@p1", TextBox1.Text)
cmd.Parameters.AddWithValue("@p2", TextBox2.Text)
cmd.Parameters.AddWithValue("@p3", TextBox3.Text)
cmd.Parameters.AddWithValue("@p4", DateTimePicker1.Value)
If Rdb1.Checked = True Then
cmd.Parameters.AddWithValue("@p5", "M")
Else
cmd.Parameters.AddWithValue("@p5", "F")
End If
cmd.Parameters.AddWithValue("@p6", ComboBox1.Text)
If (CheckBox1.Checked = True) Then
cmd.Parameters.AddWithValue("@p7", "1")
Else
cmd.Parameters.AddWithValue("@p7", "0")
End If
If (CheckBox2.Checked = True) Then
cmd.Parameters.AddWithValue("@p8", "1")
Else
cmd.Parameters.AddWithValue("@p8", "0")
End If
If (CheckBox3.Checked = True) Then
cmd.Parameters.AddWithValue("@p9", "1")
Else
cmd.Parameters.AddWithValue("@p9", "0")
End If
cmd.ExecuteNonQuery()
MsgBox("Data Updated..")
'Panel1.Enabled = False
clearedata()
'=========secondmethodFor Update=======================
'Dim row As DataRow
'row = ds.Tables(0).NewRow
'row(0) = TextBox1.Text
'row(1) = TextBox2.Text
'row(2) = TextBox3.Text
'row(3) = DateTimePicker1.Value
'If Rdb1.Checked = True Then
' row(4) = "M"
'Else
' row(4) = "F"
'End If
'row(5) = ComboBox1.Text
'If (CheckBox1.Checked = True) Then
' row(6) = "1"
'Else
' row(6) = "0"
'End If
'If (CheckBox2.Checked = True) Then
' row(7) = "1"
'Else
' row(7) = "0"
'End If
'If (CheckBox3.Checked = True) Then
' row(8) = "1"
'Else
' row(8) = "0"
'End If
'If (CheckedListBox1.CheckOnClick = True) Then
' row(6) = "1"
'Else
' row(6) = "0"
'End If
'ds.Tables(0).Rows(p).
'adp.Update(ds)
'MsgBox("Data Updates..")
End Sub
'=====================================================
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
cmd = New SqlCommand("Delete from Emp where Eno=@p1", Module1.cn)
cmd.Parameters.AddWithValue("@p1", TextBox1.Text)
cmd.ExecuteNonQuery()
MsgBox("Data is Deleted....")
'Panel1.Enabled = False
clearedata()
End Sub
'=================================================
Private Sub BtnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFirst.Click
cnt = 0
showRec()
End Sub
'==============================================
Private Sub BtnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLast.Click
cnt = ds.Tables(0).Rows.Count - 1
showRec()
End Sub
'===============================================
Private Sub BtnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNext.Click
If cnt < ds.Tables(0).Rows.Count - 1 Then
cnt = cnt + 1
Else
MsgBox("Last Record.")
End If
showRec()
End Sub
'====================================================
Private Sub BtnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrevious.Click
If cnt > 0 Then
cnt = cnt - 1
Else
MsgBox("First Record..")
End If
showRec()
End Sub
'=======
End Class
Imports System.IO
Public Class Form7
Dim cmd As New SqlCommand
Dim adp As New SqlDataAdapter
Dim ds As New DataSet
Dim p As Integer
Dim cmb As New SqlCommandBuilder
Dim cnt As Integer
'========================================
Private Sub showRec()
Dim row As DataRow
row = ds.Tables(0).Rows(cnt)
TextBox1.Text = row(0)
TextBox2.Text = row(1)
TextBox3.Text = row(2)
DateTimePicker1.Value = row(3)
If row(4) = "M" Then
Rdb1.Checked = True
Else
Rdb1.Checked = False
End If
If row(4) = "F" Then
Rdb2.Checked = True
Else
Rdb2.Checked = False
End If
ComboBox1.Text = row(5)
If row(6) = "1" Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
If row(7) = "1" Then
CheckBox2.Checked = True
Else
CheckBox2.Checked = False
End If
If row(8) = "1" Then
CheckBox3.Checked = True
Else
CheckBox3.Checked = False
End If
End Sub
'=====================================================
Private Sub DataGridView1_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
p = e.RowIndex
TextBox1.Text = DataGridView1.Rows(p).Cells(0).Value
TextBox2.Text = DataGridView1.Rows(p).Cells(1).Value
TextBox3.Text = DataGridView1.Rows(p).Cells(2).Value
DateTimePicker1.Value = DataGridView1.Rows(p).Cells(3).Value
If (DataGridView1.Rows(p).Cells(4).Value = "M") Then
Rdb1.Checked = True
Else
Rdb1.Checked = False
End If
If (DataGridView1.Rows(p).Cells(4).Value = "F") Then
Rdb2.Checked = True
Else
Rdb2.Checked = False
End If
ComboBox1.Text = DataGridView1.Rows(p).Cells(5).Value
If (DataGridView1.Rows(p).Cells(6).Value = "1") Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
If (DataGridView1.Rows(p).Cells(7).Value = "1") Then
CheckBox2.Checked = True
Else
CheckBox2.Checked = False
End If
If (DataGridView1.Rows(p).Cells(8).Value = "1") Then
CheckBox3.Checked = True
Else
CheckBox3.Checked = False
End If
End Sub
'=======================================================
Private Sub clearedata()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
Rdb1.Checked = False
Rdb2.Checked = False
ComboBox1.Text = "--Select--"
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
End Sub
'=======================================================
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Module1.Connect()
adp = New SqlDataAdapter("select * from Emp order by Eno", Module1.cn)
adp.Fill(ds)
cmb = New SqlCommandBuilder(adp)
DataGridView1.DataSource = ds.Tables(0)
clearedata()
End Sub
'=====================================================
Private Sub BtnAdd_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
Panel1.Enabled = True
clearedata()
cmd = New SqlCommand("Select max(Eno) from Emp", Module1.cn)
Dim cnt
cnt = cmd.ExecuteScalar()
If cnt Is DBNull.Value Then
cnt = 1
Else
cnt = cnt + 1
End If
TextBox1.Text = cnt
TextBox1.ReadOnly = True
TextBox2.Focus()
'Panel3.Visible = True
Panel2.Visible = False
End Sub
'==========================================================
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
'cmd = New SqlCommand("Insert into Emp values (@p1,@P2,@p3,@p4,@p5,@p6,@p7,@p8,@p9)", Module1.cn)
'cmd.Parameters.AddWithValue("@p1", TextBox1.Text)
'cmd.Parameters.AddWithValue("@p2", TextBox2.Text)
'cmd.Parameters.AddWithValue("@p3", TextBox3.Text)
'cmd.Parameters.AddWithValue("@p4", DateTimePicker1.Value)
'If Rdb1.Checked = True Then
' cmd.Parameters.AddWithValue("@p5", "M")
'Else
' cmd.Parameters.AddWithValue("@p5", "F")
'End If
'cmd.Parameters.AddWithValue("@p6", ComboBox1.Text)
'If (CheckBox1.Checked = True) Then
' cmd.Parameters.AddWithValue("@p7", "1")
'Else
' cmd.Parameters.AddWithValue("@p7", "0")
'End If
'If (CheckBox2.Checked = True) Then
' cmd.Parameters.AddWithValue("@p8", "1")
'Else
' cmd.Parameters.AddWithValue("@p8", "0")
'End If
'If (CheckBox3.Checked = True) Then
' cmd.Parameters.AddWithValue("@p9", "1")
'Else
' cmd.Parameters.AddWithValue("@p9", "0")
'End If
'cmd.ExecuteNonQuery()
'MsgBox("Saved Data..")
'Panel1.Enabled = False
'=================SecondMethod============================
Dim row As DataRow
row = ds.Tables(0).NewRow
row(0) = TextBox1.Text
row(1) = TextBox2.Text
row(2) = TextBox3.Text
row(3) = DateTimePicker1.Value
If Rdb1.Checked = True Then
row(4) = "M"
Else
row(4) = "F"
End If
row(5) = ComboBox1.Text
If (CheckBox1.Checked = True) Then
row(6) = "1"
Else
row(6) = "0"
End If
If (CheckBox2.Checked = True) Then
row(7) = "1"
Else
row(7) = "0"
End If
If (CheckBox3.Checked = True) Then
row(8) = "1"
Else
row(8) = "0"
End If
If (CheckedListBox1.CheckOnClick = True) Then
row(6) = "1"
Else
row(6) = "0"
End If
ds.Tables(0).Rows.Add(row)
adp.Update(ds)
MsgBox("Data inserted")
clearedata()
'For Each item In CheckedListBox1.CheckedItems
' row(6) = item.ToString & " "
'Next
End Sub
'==================================================
Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
cmd = New SqlCommand("Update Emp set Name=@P2,Salary=@p3,Jdate=@p4,Gender=@p5,City=@p6,Vbnet=@p7,php=@p8,Aspnet=@p9 where Eno=@p1", Module1.cn)
cmd.Parameters.AddWithValue("@p1", TextBox1.Text)
cmd.Parameters.AddWithValue("@p2", TextBox2.Text)
cmd.Parameters.AddWithValue("@p3", TextBox3.Text)
cmd.Parameters.AddWithValue("@p4", DateTimePicker1.Value)
If Rdb1.Checked = True Then
cmd.Parameters.AddWithValue("@p5", "M")
Else
cmd.Parameters.AddWithValue("@p5", "F")
End If
cmd.Parameters.AddWithValue("@p6", ComboBox1.Text)
If (CheckBox1.Checked = True) Then
cmd.Parameters.AddWithValue("@p7", "1")
Else
cmd.Parameters.AddWithValue("@p7", "0")
End If
If (CheckBox2.Checked = True) Then
cmd.Parameters.AddWithValue("@p8", "1")
Else
cmd.Parameters.AddWithValue("@p8", "0")
End If
If (CheckBox3.Checked = True) Then
cmd.Parameters.AddWithValue("@p9", "1")
Else
cmd.Parameters.AddWithValue("@p9", "0")
End If
cmd.ExecuteNonQuery()
MsgBox("Data Updated..")
'Panel1.Enabled = False
clearedata()
'=========secondmethodFor Update=======================
'Dim row As DataRow
'row = ds.Tables(0).NewRow
'row(0) = TextBox1.Text
'row(1) = TextBox2.Text
'row(2) = TextBox3.Text
'row(3) = DateTimePicker1.Value
'If Rdb1.Checked = True Then
' row(4) = "M"
'Else
' row(4) = "F"
'End If
'row(5) = ComboBox1.Text
'If (CheckBox1.Checked = True) Then
' row(6) = "1"
'Else
' row(6) = "0"
'End If
'If (CheckBox2.Checked = True) Then
' row(7) = "1"
'Else
' row(7) = "0"
'End If
'If (CheckBox3.Checked = True) Then
' row(8) = "1"
'Else
' row(8) = "0"
'End If
'If (CheckedListBox1.CheckOnClick = True) Then
' row(6) = "1"
'Else
' row(6) = "0"
'End If
'ds.Tables(0).Rows(p).
'adp.Update(ds)
'MsgBox("Data Updates..")
End Sub
'=====================================================
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
cmd = New SqlCommand("Delete from Emp where Eno=@p1", Module1.cn)
cmd.Parameters.AddWithValue("@p1", TextBox1.Text)
cmd.ExecuteNonQuery()
MsgBox("Data is Deleted....")
'Panel1.Enabled = False
clearedata()
End Sub
'=================================================
Private Sub BtnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFirst.Click
cnt = 0
showRec()
End Sub
'==============================================
Private Sub BtnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLast.Click
cnt = ds.Tables(0).Rows.Count - 1
showRec()
End Sub
'===============================================
Private Sub BtnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNext.Click
If cnt < ds.Tables(0).Rows.Count - 1 Then
cnt = cnt + 1
Else
MsgBox("Last Record.")
End If
showRec()
End Sub
'====================================================
Private Sub BtnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrevious.Click
If cnt > 0 Then
cnt = cnt - 1
Else
MsgBox("First Record..")
End If
showRec()
End Sub
'=======
End Class
No comments:
Post a Comment