ninelgorb (Programmer) Jul 26, 2005
I have one stored procedure returning data based on parameters.
I execute the stored proc for report1 with a date of 20050712 and receive data. I then populate a datagrid with this dataset.
But when I execute the stored proc with the same date, but different report(report2). I get the error.
WhenI execute the proc for both reports on the backend they both give me data.
Any ideas?
Here is my code:
Thanks,
Ninel
I have one stored procedure returning data based on parameters.
I execute the stored proc for report1 with a date of 20050712 and receive data. I then populate a datagrid with this dataset.
But when I execute the stored proc with the same date, but different report(report2). I get the error.
WhenI execute the proc for both reports on the backend they both give me data.
Any ideas?
Here is my code:
Code:
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Dim sDate As String
Dim sReport As String
Dim sEmpNameId As String
Dim sAgentId As String
Dim sErrorText As String
Dim bCreateReport As Boolean
sDate = txtDate.Text
sReport = ddlReport.SelectedValue
sEmpNameId = ddlEmployee.SelectedValue
sAgentId = ddlAgentid.SelectedValue
sProject = ddlProject.SelectedItem.Text
lblResult.Text = ""
If Len(Trim(sDate)) = 0 Then
sErrorText = "You must enter a Calldate"
lblResult.Text = sErrorText
End If
If Trim(sReport) = 0 Then
sErrorText = "You must select a Report"
lblResult.Text = sErrorText
End If
If Trim(sEmpNameId) <> 0 And Trim(sAgentId) <> 0 Then
If Trim(sEmpNameId) <> Trim(sAgentId) Then
sErrorText = "AgentId and Employee Name Must Match"
lblResult.Text = sErrorText
End If
End If
If Len(Trim(lblResult.Text)) = 0 Then
bCreateReport = CreateReport(sDate, sReport, sEmpNameId, sAgentId, sProject, sErrorText)
If Trim(sErrorText) <> "Success" Then
lblResult.Text = sErrorText
End If
End If
End Sub
Private Function CreateReport(ByVal sDate As String, ByVal sReport As String, ByVal sEmpNameId As String, _
ByVal sAgentId As String, ByVal sProject As String, ByRef sErrorText As String) As Boolean
Dim m_strConnection As String = "server=servername;Initial Catalog=dbname;user id=id;password=password;"
Dim objConn As nsSqlClient.SqlConnection
Dim returnValue As Int32
Dim objCommand As nsSqlClient.SqlCommand
Dim sSource As String
Dim sMessage As String
Dim sLine As Int32
Try
CreateReport = False
objConn = New nsSqlClient.SqlConnection
objConn.ConnectionString = m_strConnection
objConn.Open()
objCommand = New nsSqlClient.SqlCommand("uspGetExceptionReport", objConn)
objCommand.CommandType = nsData.CommandType.StoredProcedure
'Creating parameter for Procedure
objCommand.Parameters.Add(CreateParam("@RETURN_VALUE", nsData.SqlDbType.Int, 0, nsData.ParameterDirection.ReturnValue, returnValue))
objCommand.Parameters.Add(CreateParam("@sCallDate", nsData.SqlDbType.VarChar, 10, nsData.ParameterDirection.Input, sDate))
objCommand.Parameters.Add(CreateParam("@sExceptionReportId", nsData.SqlDbType.VarChar, 10, nsData.ParameterDirection.Input, sReport))
objCommand.Parameters.Add(CreateParam("@sEmployeeNameId", nsData.SqlDbType.VarChar, 20, nsData.ParameterDirection.Input, sEmpNameId))
objCommand.Parameters.Add(CreateParam("@sAgentId", nsData.SqlDbType.VarChar, 20, nsData.ParameterDirection.Input, sAgentId))
objCommand.Parameters.Add(CreateParam("@sProject", nsData.SqlDbType.VarChar, 20, nsData.ParameterDirection.Input, sProject))
objCommand.Parameters.Add(CreateParam("@sErrorText", nsData.SqlDbType.VarChar, 1000, nsData.ParameterDirection.Output, sErrorText))
objCommand.ExecuteNonQuery()
returnValue = DirectCast(objCommand.Parameters("@RETURN_VALUE").Value, Int32)
sErrorText = objCommand.Parameters("@sErrorText").Value
If returnValue <> 0 Then
sLine = 775
CreateReport = True
Exit Function
Else
End If
Dim da As New SqlDataAdapter
Dim ds As DataSet = New DataSet
da.SelectCommand = objCommand
da.Fill(ds)
grdResults.DataSource = ds
grdResults.DataBind()
If grdResults.Items.Count = 0 Then
lblResult.Visible = True
lblResult.Text = "No data to display"
End If
CreateReport = True
Finally
objCommand = Nothing
objConn.Close()
objConn = Nothing
End Try
End Function
Ninel