mohammed.kan000
New member
- Joined
- Jan 28, 2023
- Messages
- 1
- Programming Experience
- 1-3
when i start Project and click on search button every things ok
but when click once again
this error is show (This causes two bindings in the collection to bind to the same property
this my code
but when click once again
this error is show (This causes two bindings in the collection to bind to the same property
this my code
vb.net:
Imports System.Data.SQLite
Public Class Form1
Private dbcomand As String = ""
Private bindingSrc As BindingSource
Private dbName As String = "conquest.db3;"
Private dbPath As String = "D:\conquestdicomserver\data\dbase\" & dbName
Private conString As String = "Data Source=" & dbPath & "Version=3;New=False;Compress=True;"
Private connection As New SQLiteConnection(conString)
Private command As New SQLiteCommand("", connection)
Private sql As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
connection.Open()
'UpdateDatabiding()
connection.Close()
End Sub
Private Sub UpdateDatabiding(Optional cmd As SQLiteCommand = Nothing)
''TODO
Try
If cmd Is Nothing Then
command.CommandText = "SELECT StudyDate,PatientNam,StudyModal,StudyDescr,PatientsAg,PatientID FROM DICOMStudies"
Else
command = cmd
End If
Dim adapter As New SQLiteDataAdapter(command)
Dim dataSt As New DataSet()
adapter.Fill(dataSt, "DICOMStudiesList")
bindingSrc = New BindingSource()
bindingSrc.DataSource = dataSt.Tables("DICOMStudiesList")
Dim tb As TextBox
For Each ctr As Control In GroupBox1.Controls
If TypeOf ctr Is TextBox Then
tb = CType(ctr, TextBox)
tb.DataBindings.Clear()
tb.Text = ""
End If
Next
IDShowTextBox.DataBindings.Add("Text", bindingSrc, "PatientID")
NameShowTextBox.DataBindings.Add("Text", bindingSrc, "PatientNam")
DataGridView1.Enabled = True
DataGridView1.DataSource = bindingSrc
DataGridView1.AutoResizeColumns(CType(DataGridViewAutoSizeColumnsMode.AllCells, DataGridViewAutoSizeColumnsMode))
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.Columns(0).Width = 60
DisplayPosition()
Catch ex As Exception
MessageBox.Show("Data Binding Error:0 " & ex.Message.ToString())
End Try
End Sub
Private Sub DisplayPosition()
PositionLabel1.Text = "Position: " & bindingSrc.Position + 1 & "/" & bindingSrc.Count
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Psi As New ProcessStartInfo
With Psi
.FileName = "C:\Program Files\RadiAntViewer64bit\RadiAntViewer.exe"
.Arguments = "D:\conquestdicomserver\data\" & IDShowTextBox.Text
End With
Process.Start(Psi)
End Sub
Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Try
If String.IsNullOrEmpty(KeywordTextBox.Text.Trim()) Then
UpdateDatabiding()
Exit Sub
End If
sql = "SELECT StudyDate,PatientNam,StudyModal,StudyDescr,PatientsAg,PatientID FROM DICOMStudies WHERE PatientNam LIKE @keyword2"
' sql &= "WHERE PatientNam LIKE @keyword2 "
command.CommandType = CommandType.Text
command.CommandText = sql
command.Parameters.Clear()
Dim KeywordString As String = String.Format("%{0}%", KeywordTextBox.Text)
command.Parameters.AddWithValue("@keyword1", KeywordTextBox.Text)
command.Parameters.AddWithValue("@keyword2", KeywordString)
UpdateDatabiding(command)
Catch ex As Exception
MessageBox.Show("Search Error:1 " & ex.Message.ToString(),
"Error Message : iBasskung Tutorial.",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
connection.Close()
KeywordTextBox.Focus()
End Try
End Sub
End Class