I want to update Grid Row in dialogue. I am using the Grid double click event.I have two forms, on the First Form (Question_Paper) I have Grid, On double-clicking the GridRow, I am opening the new FORM(Update_Questions) on which I am updating the Records.
I want that the Record I am updated on FORM - Update_Questions get reflected on First Form(Question_Paper)
I want that the Record I am updated on FORM - Update_Questions get reflected on First Form(Question_Paper)
Code:
Question_Paper CODE
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
Dim row As DataRow = DirectCast(Me.BindingSource1.Current, DataRowView).Row
Using dialogue As New Update_Questions(row)
dialogue.ShowDialog(Me.Owner)
End Using
Dim theParent As Questions_Active = TryCast(Me.Owner, Questions_Active)
End Sub
Code:
Update_Questions CODE - On the btnSubmit_Click event, I am updating the Grid Row ,record get updated in the database but I want changes are also reflected on the form Question_Paper.
Imports System.Data.SqlClient
Public Class Update_Questions
Private data As DataRow
Dim Ques_ID, Ques, Ans1, Ans2, Ans3, Ans4, Corrct_ANS As String
Public Sub New(ByVal data As DataRow)
Ques_ID = CStr(data("Question_ID"))
Ques = CStr(data("Question"))
Ans1 = CStr(data("option_A"))
Ans2 = CStr(data("option_b"))
Ans3 = CStr(data("option_c"))
Ans4 = CStr(data("option_d"))
Corrct_ANS = CStr(data("correct_ans"))
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub Update_Questions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtQuestion.Text = Ques
txtoptA.Text = Ans1
txtoptB.Text = Ans2
txtoptC.Text = Ans3
txtoptD.Text = Ans4
txtCorrectAns.Text = Corrct_ANS
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
If (con.State = ConnectionState.Closed) Then con.Open()
cmd = New SqlCommand("update INSERT_QUESTION set Question = '" & txtQuestion.Text & "',option_A='" & txtoptA.Text & "' where Question_ID='" & Ques_ID & "'", con)
cmd.ExecuteNonQuery()
MessageBox.Show("Question Updated", "Online Examination System", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message.ToString())
Finally
If (con.State = ConnectionState.Open) Then con.Close()
End Try
End Sub