我有一个打开的子窗体(form2),它有一个带有单列的datagridview。我用数据表填充了数据。
现在,在父窗体(form1)的按钮单击事件上,我打开另一个接受某个值的窗体(form3)。我想以子格式(form2)在datagridview中插入该值。该值还在更新数据库,从数据进入datagridview。
表格:3
Dim comStr As String = "Insert into Clinicinfo values (newid(), '" & clinicnameTxt.Text & "', '" & doctorsnameTxt.Text & "', '(" & doctordegreeTxt.Text & ")', '" & clinicaddresTxt1.Text & "', '" & clinicaddressTxt2.Text & "', '" & contactnoTxt.Text & "', '" & opeaningtimeDTP.Text & "', '" & closingtimeDTP.Text & "', 'Active')"
Main.ClName = clinicnameTxt.Text
Dim comm As New SqlCommand(comStr, conn)
If MessageBox.Show("Are you sure want to save data ?", "Saving Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = vbYes Then
comm.ExecuteNonQuery()
MessageBox.Show("Data saved successfully.")
'SelectClinic.clNameDGV.Rows.Add(New String() {clinicnameTxt.Text})////TRIED
Dim adStr As String = "Select Distinct Clinic_Name from Clinicinfo Where Clinic_Status = 'Active'"
Dim Adcomm As New SqlCommand(adStr, conn)
Dim adrd As SqlDataReader
Dim dt As New DataTable
adrd = comm2.ExecuteReader
dt.Load(adrd)
Dim nf As New SelectClinic
nf.clNameDGV.Columns.Clear()
nf.clNameDGV.AllowUserToAddRows = False
nf.clNameDGV.AutoGenerateColumns = True
nf.clNameDGV.DataSource = dt
rd.Close()
End If
表格2:
comStr2 = "Select Distinct Clinic_Name from Clinicinfo Where Clinic_Status = 'Active'"
End If
Dim comm2 As New SqlCommand(comStr2, conn)
Dim rd As SqlDataReader
Dim dt As New DataTable
rd = comm2.ExecuteReader
dt.Load(rd)
'clNameDGV.Columns.Clear()
clNameDGV.AllowUserToAddRows = False
clNameDGV.AutoGenerateColumns = True
clNameDGV.DataSource = dt
clNameDGV.Refresh()
rd.Close()
表格1:
Private Sub CreateClinicAccountToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CreateClinicAccountToolStripMenuItem.Click
Dim nf As New ClinicDetails
nf.MdiParent = Me
nf.Show()
End Sub