-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Manivasakan2003
Message 1 in Discussion
Dear members, pls rectify error. for deleting & updating only ts System.Data
Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code
" Public Sub New()
MyBase.New() 'This call is required by the Windows Form Designer.
InitializeComponent() 'Add any initialization after the
InitializeComponent() call End Sub 'Form overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub 'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer 'NOTE: The following
procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button7 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button4 = New System.Windows.Forms.Button()
Me.Button5 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.TextBox3 = New System.Windows.Forms.TextBox()
Me.Button6 = New System.Windows.Forms.Button()
Me.Button7 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 160)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "MoveFirst"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(88, 160)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 1
Me.Button2.Text = "MoveNext"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(168, 160)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 2
Me.Button3.Text = "MovePrevious"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(256, 160)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 3
Me.Button4.Text = "MoveLast"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(8, 192)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 4
Me.Button5.Text = "Add"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 64)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 8
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 96)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 9
Me.TextBox2.Text = "TextBox2"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(24, 128)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.TabIndex = 10
Me.TextBox3.Text = "TextBox3"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(96, 192)
Me.Button6.Name = "Button6"
Me.Button6.TabIndex = 11
Me.Button6.Text = "Delete"
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(200, 192)
Me.Button7.Name = "Button7"
Me.Button7.TabIndex = 12
Me.Button7.Text = "Update"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(400, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button7,
Me.Button6, Me.TextBox3, Me.TextBox2, Me.TextBox1, Me.Button5, Me.Button4, Me.Button3,
Me.Button2, Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False) End Sub #End Region
Dim conn As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;;Data Source=C:\db1.mdb")
Dim ds As New DataSet()
Dim i As Integer
Dim adap As OleDbDataAdapter = New OleDbDataAdapter()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
conn.Open()
adap.TableMappings.Add("Employee", "Emp")
Dim cmd As OleDbCommand = New OleDbCommand("select * from employee", conn)
cmd.CommandType = CommandType.Text
adap.SelectCommand = cmd
ds = New DataSet("Emp")
adap.Fill(ds)
assign()
End Sub
Private Sub assign()
TextBox1.Text = ds.Tables(0).Rows(i)(0)
TextBox2.Text = ds.Tables(0).Rows(i)(1)
TextBox3.Text = ds.Tables(0).Rows(i)(2)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
i = 0
assign()
MsgBox("First Record") End Sub Private Sub Button2_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
i = i + 1
If i < ds.Tables(0).Rows.Count Then
assign()
Else
MsgBox(" Last Record Reached ")
i = i - 1
End If
End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
i = i - 1
If i < 0 Then
MsgBox(" First Record Reached ")
i = i + 1
Else
assign()
End If
End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
i = ds.Tables(0).Rows.Count - 1
assign()
MsgBox("Last Record")
End Sub
Private Sub cleartext()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Try Dim ds1 As New DataSet()
Dim dr As DataRow
Dim insadap As OleDbDataAdapter = New OleDbDataAdapter("select * from
employee", conn)
insadap.InsertCommand = New OleDbCommand("insert into Employee
values(?,?,?)", conn)
insadap.InsertCommand.Parameters.Add("@Empno", OleDbType.VarChar, 20,
"Empno")
insadap.InsertCommand.Parameters.Add("@EmpName", OleDbType.VarChar, 20,
"EmpName")
insadap.InsertCommand.Parameters.Add("@Dno", OleDbType.VarChar, 20, "Dno")
insadap.Fill(ds1, "Emp")
dr = ds1.Tables(0).NewRow
ds1.Tables(0).Rows.Add(dr)
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox3.Text
insadap.Update(ds1, "Emp")
MsgBox("Record Inserted", MsgBoxStyle.Information, "ADO.net")
Catch InsErr As Exception
MsgBox(InsErr.Message)
End Try
End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Try
Dim ds2 As New DataSet()
Dim deladap As OleDbDataAdapter = New OleDbDataAdapter("select * from
employee", conn)
deladap.DeleteCommand = New OleDbCommand("delete from employee where EmpNo
= ?", conn)
deladap.DeleteCommand.Parameters.Add("@EmpNo", OleDbType.VarChar, 20,
"EmpNo")
deladap.Fill(ds2, "Emp")
ds2.Tables(0).Rows(3).Delete()
deladap.Update(ds2, "Emp")
MsgBox("Deleted")
Catch DelErr As Exception
MsgBox(DelErr.Message)
End Try End Sub Private Sub Button7_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles Button7.Click try
Dim updadap As OleDbDataAdapter = New OleDbDataAdapter("select * from
employee", conn)
updadap.UpdateCommand = New OleDbCommand("update employee set EmpName=?, Dno=?
where EmpNo=?", conn) Dim workparam As OleDbParameter =
updadap.UpdateCommand.Parameters.Add("@EmpNo", OleDbType.VarChar, 20, "@EmpNo")
Dim workparam1 As OleDbParameter =
updadap.UpdateCommand.Parameters.Add("@EmpName", OleDbType.varcyhar, 20, "@EmpName")
Dim workparam2 As OleDbParameter =
updadap.UpdateCommand.Parameters.Add("@Dno", OleDbType.VarChar, 20, "Dno")
MsgBox("Parameters Created") workparam.SourceColumn = "deptno"
workparam.SourceVersion = DataRowVersion.Original
Dim updds As DataSet = New DataSet()
updadap.Fill(updds, "emp")
MsgBox("Dataset Filled")
Dim ccol As DataColumn = updds.Tables(0).Columns(0)
ccol.DefaultValue = CInt(TextBox1.Text)
Dim crow As DataRow = updds.Tables(0).Rows(0)
MsgBox("Column field selected")
crow(2) = TextBox3.Text
updadap.Update(updds)
MsgBox("Updated") catch up as exception msgbox(up.message) end try
End Sub
End Class
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]