Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Can not Search in and Edit DB in the same times (and same Windows Form) by using DataGridView

$
0
0
Hi
I'm have DataGridView in a Windows Form with some data in it and I have button for edit, I want to search for row by using TextBox and button and when I find the wanted row I will change it and click edit button,when I edit any row (without using search button) and press edit the DB is Updated , my problem is that: when I search for specific row and find it then edit the data and press edit button the data in DB don't updated, please help, I'm use this code:

   

Imports System.Data.SqlClient Public Class Form9 Private sqlConn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Clinic System\Clinic System\ClinicDB.mdf;Integrated Security=True;User Instance=True") Private cmdSelect, cmdDelete As String Private daEmployees As New SqlDataAdapter("Select * From History", sqlConn) Private sqlCmndBuilder As New SqlCommandBuilder(daEmployees) Private myDS As New DataSet Private Sub HistoryBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.Validate() Me.HistoryBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.ClinicDBDataSet3) End Sub Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load daEmployees.Fill(myDS, "History") HistoryDataGridView.DataSource = myDS.Tables(0) End Sub Private Sub ButtonSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSearch.Click Try Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Clinic System\Clinic System\ClinicDB.mdf;Integrated Security=True;User Instance=True") Dim d1 As New SqlDataAdapter("Select * from History Where Name like '%" & TextBox1.Text & "%'", con) Dim d2 As New DataTable d1.Fill(d2) HistoryDataGridView.DataSource = d2 Catch ex As Exception MessageBox.Show("Err.Discription") End Try End Sub Private Sub ButtonEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEdit.Click daEmployees.Update(myDS.Tables(0)) MsgBox("Patient Details Updated!") End Sub




Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>