Hi,
I have the following code;
At run time when I click the button I receive the error -Code:Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click Dim strConn As String strConn = ConfigurationManager.ConnectionStrings("CCMSConnectionString").ConnectionString Dim conn As New SqlConnection(strConn) 'Dim nextconn As New SqlConnection(strConn) conn.Open() Dim strSql As String strSql = "INSERT INTO dbo.TblChangeControlDet (RequestBy, CreatedBy, ChangeType, TechnicalPerson, Req, BusImp,ChangeRaisedDate, PeerRvw) VALUES (@RequestBy, @CreatedBy, @ChangeType, @TechnicalPerson, @Req, @BusImp,@ChangeRaisedDate, @PeerRvw )" Dim cmd As New SqlCommand(strSql, conn) With cmd.Parameters .AddWithValue("@RequestBy", Me.cmbchngreq.SelectedItem.ToString) .AddWithValue("@CreatedBy", Me.cmbchngcrt.SelectedItem.ToString) .AddWithValue("@ChangeType", Me.cmbchngtyp.SelectedItem.ToString) .AddWithValue("@TechnicalPerson", Me.cmbTechname.SelectedItem.ToString) .AddWithValue("@Req", txtreq.Text) .AddWithValue("@BusImp", txtbusimp.Text) .AddWithValue("@ChangeRaisedDate", DateTime.Now.ToString("dd\/MM\/yyyy HH:mm:ss")) .AddWithValue("@PeerRvw", Me.cmbpeername.SelectedItem.ToString) End With cmd.ExecuteNonQuery() Dim query As String Dim RefID As New System.Data.SqlClient.SqlCommand(("Select RefNo From dbo.QryRefNo"), conn) Try Using Autoreader As System.Data.SqlClient.SqlDataReader = RefID.ExecuteReader() While Autoreader.Read() Dim RefNo As String = (Autoreader.GetValue(0)) query = "UPDATE dbo.TblChangeControlDet SET RefNo = @RefNo WHERE ChangeRaisedDate = @ChangeRaisedDate" cmd = New SqlCommand(query, conn) cmd.Parameters.AddWithValue("@RefNo", RefNo) cmd.Parameters.AddWithValue("@ChangeRaisedDate", DateTime.Now.ToString("dd\/MM\/yyyy HH:mm:ss")) cmd.ExecuteNonQuery() End While End Using Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "Spare Elements") End Try conn.Close() End Sub
'There is already an open DataReader associated with this Command which must be closed first".
The INSERT works fine the problem us with the UPDATE statement.
Thanks


Reply With Quote
Bookmarks