User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 397,697 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,520 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
May 25th, 2005
Views: 36,863
Connection To Access Database and Save,Retrieve,Update
D:\access\try.mdb=The Address of the Access database table 'Try'.
Take a module as ModMain(Copy the code)
table fields: idno,name,designation.(idno=auto number)
textBoxes=TxtName,TxtDesignation And Combobox=CboRetrieve
buttons=new,save,retrieve,exit
vbnet Syntax | 4 stars
  1. Module ModMain
  2. Public Const OLEDB_CONNECTION_STRING As String = _
  3. "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Database Password=soumya;Data Source=D:\access\try.mdb;Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False"
  4. '"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source=D:\access\try.mdb ;Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
  5.  
  6.  
  7. '"workstation id=USER21;packet size=4096;integrated security=SSPI;data source=USER12;persist security info=False;initial catalog=Northwind"
  8.  
  9. Public Const ConnectionString As String = OLEDB_CONNECTION_STRING
  10. Public mode As Boolean
  11. Public DSTry As New DataSet
  12. 'Public DSTry As New System.Data.DataSet
  13. Public Const Select_Command As String = "select idno,name,designation from try ORDER BY IDNO"
  14. End Module
  15.  
  16.  
  17. #Region "General Declarations"
  18. Option Explicit On
  19. 'Option Strict On
  20. Imports System.Data
  21. Imports System.Data.OleDb
  22. #End Region
  23.  
  24. Public Class Form1
  25. Inherits System.Windows.Forms.Form
  26.  
  27. #Region " Windows Form Designer generated code "
  28. 'the follwing matter within brace will be automatically generated
  29. [
  30. Public Sub New()
  31. MyBase.New()
  32.  
  33. 'This call is required by the Windows Form Designer.
  34. InitializeComponent()
  35.  
  36. 'Add any initialization after the InitializeComponent() call
  37.  
  38. End Sub
  39.  
  40. 'Form overrides dispose to clean up the component list.
  41. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  42. If disposing Then
  43. If Not (components Is Nothing) Then
  44. components.Dispose()
  45. End If
  46. End If
  47. MyBase.Dispose(disposing)
  48. End Sub
  49.  
  50. 'Required by the Windows Form Designer
  51. Private components As System.ComponentModel.IContainer
  52.  
  53. 'NOTE: The following procedure is required by the Windows Form Designer
  54. 'It can be modified using the Windows Form Designer.
  55. 'Do not modify it using the code editor.
  56. Friend WithEvents TxtIDno As System.Windows.Forms.TextBox
  57. Friend WithEvents Label1 As System.Windows.Forms.Label
  58. Friend WithEvents Label2 As System.Windows.Forms.Label
  59. Friend WithEvents Label3 As System.Windows.Forms.Label
  60. Friend WithEvents BtnNew As System.Windows.Forms.Button
  61. Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
  62. Friend WithEvents BtnSave As System.Windows.Forms.Button
  63. Friend WithEvents BtnRetrieve As System.Windows.Forms.Button
  64. Friend WithEvents BtnExit As System.Windows.Forms.Button
  65. Friend WithEvents CboRetrieve As System.Windows.Forms.ComboBox
  66. Friend WithEvents TxtName As System.Windows.Forms.TextBox
  67. Friend WithEvents TxtDesignation As System.Windows.Forms.TextBox
  68. Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
  69. Friend WithEvents Label4 As System.Windows.Forms.Label
  70. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  71. Me.TxtIDno = New System.Windows.Forms.TextBox
  72. Me.Label1 = New System.Windows.Forms.Label
  73. Me.TxtName = New System.Windows.Forms.TextBox
  74. Me.Label2 = New System.Windows.Forms.Label
  75. Me.Label3 = New System.Windows.Forms.Label
  76. Me.TxtDesignation = New System.Windows.Forms.TextBox
  77. Me.BtnNew = New System.Windows.Forms.Button
  78. Me.GroupBox1 = New System.Windows.Forms.GroupBox
  79. Me.BtnExit = New System.Windows.Forms.Button
  80. Me.BtnRetrieve = New System.Windows.Forms.Button
  81. Me.BtnSave = New System.Windows.Forms.Button
  82. Me.CboRetrieve = New System.Windows.Forms.ComboBox
  83. Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
  84. Me.Label4 = New System.Windows.Forms.Label
  85. Me.GroupBox1.SuspendLayout()
  86. Me.SuspendLayout()
  87. '
  88. 'TxtIDno
  89. '
  90. Me.TxtIDno.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
  91. Me.TxtIDno.Location = New System.Drawing.Point(112, 32)
  92. Me.TxtIDno.Name = "TxtIDno"
  93. Me.TxtIDno.Size = New System.Drawing.Size(64, 20)
  94. Me.TxtIDno.TabIndex = 0
  95. Me.TxtIDno.Text = ""
  96. '
  97. 'Label1
  98. '
  99. Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  100. Me.Label1.ForeColor = System.Drawing.SystemColors.HotTrack
  101. Me.Label1.Location = New System.Drawing.Point(56, 32)
  102. Me.Label1.Name = "Label1"
  103. Me.Label1.Size = New System.Drawing.Size(48, 16)
  104. Me.Label1.TabIndex = 1
  105. Me.Label1.Text = "ID No"
  106. '
  107. 'TxtName
  108. '
  109. Me.TxtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
  110. Me.TxtName.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  111. Me.TxtName.ForeColor = System.Drawing.Color.Black
  112. Me.TxtName.Location = New System.Drawing.Point(112, 72)
  113. Me.TxtName.Name = "TxtName"
  114. Me.TxtName.Size = New System.Drawing.Size(144, 22)
  115. Me.TxtName.TabIndex = 2
  116. Me.TxtName.Text = ""
  117. '
  118. 'Label2
  119. '
  120. Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  121. Me.Label2.Location = New System.Drawing.Point(56, 72)
  122. Me.Label2.Name = "Label2"
  123. Me.Label2.Size = New System.Drawing.Size(48, 16)
  124. Me.Label2.TabIndex = 3
  125. Me.Label2.Text = "Name"
  126. '
  127. 'Label3
  128. '
  129. Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  130. Me.Label3.Location = New System.Drawing.Point(32, 112)
  131. Me.Label3.Name = "Label3"
  132. Me.Label3.Size = New System.Drawing.Size(72, 16)
  133. Me.Label3.TabIndex = 4
  134. Me.Label3.Text = "Designation"
  135. '
  136. 'TxtDesignation
  137. '
  138. Me.TxtDesignation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
  139. Me.TxtDesignation.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  140. Me.TxtDesignation.ForeColor = System.Drawing.Color.Black
  141. Me.TxtDesignation.Location = New System.Drawing.Point(112, 112)
  142. Me.TxtDesignation.Name = "TxtDesignation"
  143. Me.TxtDesignation.Size = New System.Drawing.Size(144, 22)
  144. Me.TxtDesignation.TabIndex = 5
  145. Me.TxtDesignation.Text = ""
  146. '
  147. 'BtnNew
  148. '
  149. Me.BtnNew.BackColor = System.Drawing.Color.Gainsboro
  150. Me.BtnNew.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  151. Me.BtnNew.ForeColor = System.Drawing.SystemColors.HotTrack
  152. Me.BtnNew.Location = New System.Drawing.Point(8, 24)
  153. Me.BtnNew.Name = "BtnNew"
  154. Me.BtnNew.Size = New System.Drawing.Size(64, 32)
  155. Me.BtnNew.TabIndex = 6
  156. Me.BtnNew.Text = "New"
  157. '
  158. 'GroupBox1
  159. '
  160. Me.GroupBox1.Controls.Add(Me.BtnExit)
  161. Me.GroupBox1.Controls.Add(Me.BtnRetrieve)
  162. Me.GroupBox1.Controls.Add(Me.BtnSave)
  163. Me.GroupBox1.Controls.Add(Me.BtnNew)
  164. Me.GroupBox1.Location = New System.Drawing.Point(8, 160)
  165. Me.GroupBox1.Name = "GroupBox1"
  166. Me.GroupBox1.Size = New System.Drawing.Size(280, 72)
  167. Me.GroupBox1.TabIndex = 7
  168. Me.GroupBox1.TabStop = False
  169. '
  170. 'BtnExit
  171. '
  172. Me.BtnExit.BackColor = System.Drawing.Color.Gainsboro
  173. Me.BtnExit.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  174. Me.BtnExit.Location = New System.Drawing.Point(206, 24)
  175. Me.BtnExit.Name = "BtnExit"
  176. Me.BtnExit.Size = New System.Drawing.Size(64, 32)
  177. Me.BtnExit.TabIndex = 9
  178. Me.BtnExit.Text = "Exit"
  179. '
  180. 'BtnRetrieve
  181. '
  182. Me.BtnRetrieve.BackColor = System.Drawing.Color.Gainsboro
  183. Me.BtnRetrieve.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  184. Me.BtnRetrieve.Location = New System.Drawing.Point(140, 24)
  185. Me.BtnRetrieve.Name = "BtnRetrieve"
  186. Me.BtnRetrieve.Size = New System.Drawing.Size(64, 32)
  187. Me.BtnRetrieve.TabIndex = 8
  188. Me.BtnRetrieve.Text = "Retrieve"
  189. '
  190. 'BtnSave
  191. '
  192. Me.BtnSave.BackColor = System.Drawing.Color.Gainsboro
  193. Me.BtnSave.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  194. Me.BtnSave.ForeColor = System.Drawing.SystemColors.HotTrack
  195. Me.BtnSave.Location = New System.Drawing.Point(74, 24)
  196. Me.BtnSave.Name = "BtnSave"
  197. Me.BtnSave.Size = New System.Drawing.Size(64, 32)
  198. Me.BtnSave.TabIndex = 7
  199. Me.BtnSave.Text = "Save"
  200. '
  201. 'CboRetrieve
  202. '
  203. Me.CboRetrieve.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
  204. Me.CboRetrieve.Location = New System.Drawing.Point(112, 32)
  205. Me.CboRetrieve.Name = "CboRetrieve"
  206. Me.CboRetrieve.Size = New System.Drawing.Size(64, 21)
  207. Me.CboRetrieve.TabIndex = 8
  208. '
  209. 'LinkLabel1
  210. '
  211. Me.LinkLabel1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
  212. Me.LinkLabel1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  213. Me.LinkLabel1.Location = New System.Drawing.Point(96, 240)
  214. Me.LinkLabel1.Name = "LinkLabel1"
  215. Me.LinkLabel1.Size = New System.Drawing.Size(112, 16)
  216. Me.LinkLabel1.TabIndex = 9
  217. Me.LinkLabel1.TabStop = True
  218. Me.LinkLabel1.Text = "Data Grid View"
  219. '
  220. 'Label4
  221. '
  222. Me.Label4.Location = New System.Drawing.Point(8, 232)
  223. Me.Label4.Name = "Label4"
  224. Me.Label4.Size = New System.Drawing.Size(280, 32)
  225. Me.Label4.TabIndex = 10
  226. '
  227. 'Form1
  228. '
  229. Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  230. Me.BackColor = System.Drawing.SystemColors.ActiveBorder
  231. Me.ClientSize = New System.Drawing.Size(288, 261)
  232. Me.Controls.Add(Me.LinkLabel1)
  233. Me.Controls.Add(Me.CboRetrieve)
  234. Me.Controls.Add(Me.TxtIDno)
  235. Me.Controls.Add(Me.TxtDesignation)
  236. Me.Controls.Add(Me.TxtName)
  237. Me.Controls.Add(Me.GroupBox1)
  238. Me.Controls.Add(Me.Label3)
  239. Me.Controls.Add(Me.Label2)
  240. Me.Controls.Add(Me.Label1)
  241. Me.Controls.Add(Me.Label4)
  242. Me.ForeColor = System.Drawing.SystemColors.HotTrack
  243. Me.Name = "Form1"
  244. Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  245. Me.Text = "Form1"
  246. Me.GroupBox1.ResumeLayout(False)
  247. Me.ResumeLayout(False)
  248.  
  249. End Sub
  250.  
  251. ]
  252. #End Region
  253.  
  254. #Region "Load Events"
  255. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  256. CboRetrieve.Visible = False
  257. CboRetrieve.Enabled = False
  258. TxtIDno.Enabled = False
  259. mode = True
  260. End Sub
  261. #End Region
  262.  
  263. #Region "Procedural Declarations"
  264.  
  265. Private Sub Count()
  266. Dim cnSQL As OleDbConnection
  267. Dim cmSQL As OleDbCommand
  268. Dim drSQL As OleDbDataReader
  269. Dim strSQL As String
  270.  
  271. Try
  272.  
  273. strSQL = "select count(*) from try"
  274.  
  275. cnSQL = New OleDbConnection(ConnectionString)
  276. cnSQL.Open()
  277.  
  278. cmSQL = New OleDbCommand(strSQL, cnSQL)
  279. drSQL = cmSQL.ExecuteReader()
  280.  
  281. If drSQL.Read() Then
  282.  
  283. TxtIDno.Text = drSQL.Item("idno").ToString()
  284.  
  285. End If
  286.  
  287. drSQL.Close()
  288. cnSQL.Close()
  289. cmSQL.Dispose()
  290. cnSQL.Dispose()
  291.  
  292. Catch e As OleDbException
  293. MsgBox(e.Message, MsgBoxStyle.Critical, "oledb Error")
  294.  
  295. Catch e As Exception
  296. MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
  297. End Try
  298.  
  299. End Sub
  300.  
  301. Private Sub clearCombo()
  302. CboRetrieve.SelectedIndex = -1
  303. CboRetrieve.SelectedItem = 0
  304. CboRetrieve.SelectedValue = 0
  305. CboRetrieve.SelectionLength = 0
  306. End Sub
  307. Private Sub combo()
  308. 'Dim strSql As String = "SELECT * FROM try order by idno"
  309. Dim adap As New OleDb.OleDbDataAdapter(Select_Command, ConnectionString)
  310. adap.Fill(DSTry, "try")
  311. adap.Dispose()
  312. CboRetrieve.DataSource = DSTry.Tables("try")
  313. CboRetrieve.DisplayMember = DSTry.Tables("try").Columns(0).ColumnName
  314. CboRetrieve.ValueMember = DSTry.Tables("try").Columns(0).ColumnName
  315.  
  316. End Sub
  317.  
  318. Private Sub Save_me()
  319. Dim DAdapter As New OleDb.OleDbDataAdapter(Select_Command, ConnectionString)
  320.  
  321. Try
  322. Me.BindingContext(DSTry, _
  323. "try").EndCurrentEdit()
  324.  
  325. DAdapter.Update(DSTry, _
  326. "try")
  327.  
  328. MessageBox.Show("Saved Successfully")
  329.  
  330. Catch eSave As System.Exception
  331. MessageBox.Show(eSave.Message)
  332.  
  333. End Try
  334.  
  335. End Sub
  336.  
  337. 'Dim strSql As String = "insert into try(name,designation) values"
  338.  
  339.  
  340. Private Sub CheckEntry()
  341. 'Dim cnSQL As OleDbConnection
  342. 'Dim cmSQL As OleDbCommand
  343. 'Dim strSQL As String
  344. 'Dim verSqlRed As OleDbDataReader
  345.  
  346. 'Try
  347. 'strSQL = "select * from try" & _
  348. '" where idno = " & TxtIDno.Text & ""
  349.  
  350.  
  351. 'cnSQL = New OleDbConnection(ConnectionString)
  352. 'cnSQL.Open()
  353.  
  354. 'cmSQL = New OleDbCommand(strSQL, cnSQL)
  355. 'verSqlRed = cmSQL.ExecuteReader
  356. 'If verSqlRed.Read = True Then
  357. ' MessageBox.Show("This ID Number Already Exists")
  358. ' TxtIDno.Text = ""
  359. ' TxtIDno.Focus()
  360. ' Exit Sub
  361. If mode = True Then
  362. ' Dim msg As String
  363. ' Dim title As String
  364. ' Dim style As MsgBoxStyle
  365. ' Dim response As MsgBoxResult
  366. ' msg = "The Mobile Number Already Exists,Do you want to update the data?"
  367. ' style = MsgBoxStyle.DefaultButton2 Or _
  368. ' MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
  369. ' title = "Confirmation of Saving data" ' Define title.
  370. ' response = MsgBox(msg, style, title)
  371. ' If response = MsgBoxResult.No Then
  372. ' Exit Sub
  373. ' Else
  374. ' Call updatedata()
  375. ' End If
  376. 'Else
  377. Call SaveData()
  378. '''Call Save_me()
  379. Else
  380. Call updatedata()
  381. '''Call Save_me()
  382. End If
  383.  
  384.  
  385. ' cnSQL.Close()
  386. ' cmSQL.Dispose()
  387. ' cnSQL.Dispose()
  388.  
  389. 'Catch e As OleDbException
  390. ' MsgBox(e.Message, MsgBoxStyle.Critical, "Oledb Error")
  391.  
  392. 'Catch e As Exception
  393. ' MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
  394. 'End Try
  395. End Sub
  396. Private Sub SaveData()
  397. If TxtName.Text = "" Or TxtDesignation.Text = "" Then
  398. MessageBox.Show("Fill Data into Every Field")
  399. Exit Sub
  400. Else
  401.  
  402. Dim msg As String
  403. Dim title As String
  404. Dim style As MsgBoxStyle
  405. Dim response As MsgBoxResult
  406. msg = "Do you want to save the data?"
  407. style = MsgBoxStyle.DefaultButton2 Or _
  408. MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
  409. title = "Confirmation of Saving data" ' Define title.
  410. response = MsgBox(msg, style, title)
  411. If response = MsgBoxResult.No Then
  412. Exit Sub
  413. Else
  414. Dim cnSQL As OleDbConnection
  415. Dim cmSQL As OleDbCommand
  416. Dim strSQL As String
  417. Dim intRowsAffected As Integer
  418.  
  419. Try
  420. strSQL = "insert into try(name,designation)" & _
  421. " values('" & _
  422. TxtName.Text & "', '" & _
  423. TxtDesignation.Text & "')"
  424.  
  425. cnSQL = New OleDbConnection(ConnectionString)
  426. cnSQL.Open()
  427.  
  428. cmSQL = New OleDbCommand(strSQL, cnSQL)
  429. cmSQL.ExecuteNonQuery()
  430.  
  431. cnSQL.Close()
  432. cmSQL.Dispose()
  433. cnSQL.Dispose()
  434.  
  435. MessageBox.Show("Saved Successfully")
  436. Call clear()
  437. Catch Exp As OleDbException
  438. MsgBox(Exp.Message, MsgBoxStyle.Critical, "Oledb Error")
  439.  
  440. Catch Exp As Exception
  441. MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
  442. End Try
  443. End If
  444. End If
  445. End Sub
  446.  
  447. Private Sub clear()
  448. 'TxtIDno.Text = ""
  449. TxtIDno.Visible = True
  450. TxtIDno.Enabled = False
  451. TxtName.Text = ""
  452. TxtDesignation.Text = ""
  453. End Sub
  454.  
  455. Private Sub updatedata()
  456.  
  457. If TxtName.Text = "" Or TxtDesignation.Text = "" Then
  458. MessageBox.Show("Fill Data into Every Field")
  459. Exit Sub
  460. Else
  461. Dim cnSQL As OleDbConnection
  462. Dim cmSQL As OleDbCommand
  463. Dim strSQL As String
  464. Dim intRowsAffected As Integer
  465.  
  466. Try
  467. strSQL = "UPDATE try SET" & _
  468. " Name = '" & TxtName.Text & "'" & _
  469. " ,designation = '" & TxtDesignation.Text & "'" & _
  470. " WHERE idno = " & CboRetrieve.Text & ""
  471.  
  472. cnSQL = New OleDbConnection(ConnectionString)
  473. cnSQL.Open()
  474.  
  475. cmSQL = New OleDbCommand(strSQL, cnSQL)
  476. intRowsAffected = cmSQL.ExecuteNonQuery()
  477.  
  478. If intRowsAffected <> 1 Then
  479. MsgBox("Update Failed.", MsgBoxStyle.Critical, "Update")
  480. End If
  481.  
  482. cnSQL.Close()
  483. cmSQL.Dispose()
  484. cnSQL.Dispose()
  485.  
  486. MessageBox.Show("Updated Successfully")
  487. Catch e As OleDbException
  488. MsgBox(e.Message, MsgBoxStyle.Critical, "Oledb Error")
  489.  
  490. Catch e As Exception
  491. MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
  492. End Try
  493. End If
  494. clear()
  495. clearCombo()
  496. End Sub
  497.  
  498. Private Sub PopulateForm()
  499. Dim cnSQL As OleDbConnection
  500. Dim cmSQL As OleDbCommand
  501. Dim drSQL As OleDbDataReader
  502. Dim strSQL As String
  503.  
  504. Try
  505.  
  506. strSQL = "SELECT name, " & _
  507. "designation " & _
  508. "FROM try " & _
  509. "WHERE idno = " & CboRetrieve.Text & ""
  510.  
  511.  
  512.  
  513. cnSQL = New OleDbConnection(ConnectionString)
  514. cnSQL.Open()
  515.  
  516. cmSQL = New OleDbCommand(strSQL, cnSQL)
  517. drSQL = cmSQL.ExecuteReader()
  518.  
  519. If drSQL.Read() Then
  520.  
  521. TxtName.Text = drSQL.Item("NAME").ToString()
  522. TxtDesignation.Text() = drSQL.Item("designation").ToString()
  523.  
  524. End If
  525.  
  526. drSQL.Close()
  527. cnSQL.Close()
  528. cmSQL.Dispose()
  529. cnSQL.Dispose()
  530.  
  531. Catch e As OleDbException
  532. MsgBox(e.Message, MsgBoxStyle.Critical, "oledb Error")
  533.  
  534. Catch e As Exception
  535. MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
  536. End Try
  537.  
  538. End Sub
  539. #End Region
  540.  
  541. #Region "Click Events"
  542.  
  543.  
  544. Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
  545. 'Call CheckEntry()
  546. Call Save_me()
  547. 'Dim DAdapter As New OleDb.OleDbDataAdapter(Select_Command, ConnectionString)
  548.  
  549. 'Try
  550. ' Me.BindingContext(DSTry, _
  551. ' "Try").EndCurrentEdit()
  552.  
  553. ' DAdapter.Update(DSTry, _
  554. ' "Try")
  555.  
  556. ' MessageBox.Show("Saved Successfully")
  557.  
  558. 'Catch eSave As System.Exception
  559. ' MessageBox.Show(eSave.Message)
  560.  
  561. 'End Try
  562.  
  563. End Sub
  564.  
  565. Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNew.Click
  566. mode = True
  567. CboRetrieve.Visible = False
  568. CboRetrieve.Enabled = False
  569. TxtIDno.Visible = True
  570. TxtIDno.Enabled = True
  571. TxtIDno.Focus()
  572. Call clear()
  573. 'Call Count()
  574. End Sub
  575.  
  576. Private Sub BtnRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRetrieve.Click
  577. mode = False
  578. CboRetrieve.Visible = True
  579. TxtIDno.Visible = False
  580. CboRetrieve.Enabled = True
  581. TxtIDno.Enabled = False
  582. Call combo()
  583. Call clearCombo()
  584. End Sub
  585.  
  586. Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
  587. End
  588. 'Me.Hide()
  589. End Sub
  590. Private Sub CboRetrieve_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboRetrieve.SelectionChangeCommitted
  591. PopulateForm()
  592. End Sub
  593. #End Region
  594.  
  595.  
  596. Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
  597. Dim form1 As New FrmGrid
  598. form1.Show()
  599. Call clearCombo()
  600. Call clear()
  601. End Sub
  602. End Class
  603.