This is a desperate plea for some help! I am lost!
I have a database in SQL Server containing two Stored Procedures: One reads all it's data to a Windows Form using textboxes in Visual Studio and the other is suppose to read all it's data into a Datagridview on the same form.
Here is where I am lost:
I am trying to take the REP_ID number displayed in the textbox from the first Stored Procedure called
GetAllReps and feed it back to the other Store Procedure called GetSalaryByReps, finally I need to display the result of GetSalaryByReps on the DataGridview.
The GetSalaryByReps stored procedure requires an ID number which I must get form the textbox use to display the REP_ID on the form.
Here is my full code:
Code:
Imports System.Data
Imports System.Data.SqlClient
Public Class frmBindingData
Dim objConnection As New SqlConnection _
("Server=test;Database=test;Trusted_Connection=True")
Dim objDataAdapter As New SqlDataAdapter("EXEC GetAllReps", objConnection)
Dim objDataSet As DataSet
Dim objDataView As DataView
Dim objCurrencyManager As CurrencyManager
Private Sub FillDataSetAndView()
' Initialize a new instance of the DataSet object..
objDataSet = New DataSet()
' Fill the DataSet object with data..
objDataAdapter.Fill(objDataSet, "SALES_REP")
' Set the DataView object to the DataSet object..
objDataView = New DataView(objDataSet.Tables("SALES_REP"))
objDataView.Sort = "REP_ID ASC"
objCurrencyManager = CType(Me.BindingContext(objDataView), CurrencyManager)
End Sub
Private Sub BindFields()
' Clear any previous bindings..
txtIDNumber.DataBindings.Clear()
txtFirstName.DataBindings.Clear()
txtLastName.DataBindings.Clear()
txtDateHire.DataBindings.Clear()
txtCommision.DataBindings.Clear()
' Add new bindings to the DataView object.
txtIDNumber.DataBindings.Add("Text", objDataView, "REP_ID")
txtFirstName.DataBindings.Add("Text", objDataView, "FIRST_NAME")
txtLastName.DataBindings.Add("Text", objDataView, "LAST_NAME")
txtDateHire.DataBindings.Add("text", objDataView, "HIRE_DATE")
txtCommision.DataBindings.Add("Text", objDataView, "COMMISION")
' Display a ready status..
ToolStripStatusLabel1.Text = "Ready"
End Sub
----------I started to create this to get the REP_ID from the text box into the Stored Procedure but I am not sure I am getting this done the right way.------------
Private Sub rntRepId()
objConnection.Open()
Dim objCommand As SqlCommand = New SqlCommand()
objCommand.Connection = objConnection
objCommand.CommandType = CommandType.StoredProcedure
objCommand.CommandText = "GetSalaryByReps"
objCommand.Parameters.AddWithValue("@REP_ID", txtIDNumber.Text)
objCommand.ExecuteNonQuery()
objConnection.Close()
End Sub
----------------------------------------------------------------------------
Private Sub ShowPosition()
'Always format the number in the txtPrice field to include cents
Try
txtCommision.Text = Format(CType(txtCommision.Text, Decimal), "c")
Catch e As System.Exception
txtCommision.Text = "0"
txtCommision.Text = Format(CType(txtCommision.Text, Decimal), "c")
End Try
' Display the current position and the number of records
txtRecordPosition.Text = objCurrencyManager.Position + 1 & _
" of " & objCurrencyManager.Count()
End Sub
Private Sub grpDataDisplay_Enter(sender As System.Object, e As System.EventArgs) Handles grpDataDisplay.Enter
End Sub
Private Sub StatusStrip1_ItemClicked(sender As System.Object, e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles StatusStrip1.ItemClicked
End Sub
Private Sub frmBindingData_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
' Fill the DataSet and bind the fields..
rntRepId()
FillDataSetAndView()
BindFields()
' Show the current record position..
ShowPosition()
End Sub
Private Sub btnMoveFirst_Click(sender As System.Object, e As System.EventArgs) Handles btnMoveFirst.Click
' Set the record position to the first record..
objCurrencyManager.Position = 0
' Show the current record position..
ShowPosition()
End Sub
Private Sub btnMovePrevious_Click(sender As System.Object, e As System.EventArgs) Handles btnMovePrevious.Click
' Move to the previous record..
objCurrencyManager.Position -= 1
' Show the current record position..
ShowPosition()
End Sub
Private Sub btnMoveNext_Click(sender As System.Object, e As System.EventArgs) Handles btnMoveNext.Click
' Move to the next record..
objCurrencyManager.Position += 1
' Show the current record position..
ShowPosition()
End Sub
Private Sub btnMoveLast_Click(sender As System.Object, e As System.EventArgs) Handles btnMoveLast.Click
' Set the record position to the last record..
objCurrencyManager.Position = objCurrencyManager.Count - 1
' Show the current record position..
ShowPosition()
End Sub
Private Sub txtRecordPosition_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtRecordPosition.TextChanged
End Sub
Private Sub ToolStripStatusLabel1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripStatusLabel1.Click
End Sub
Private Sub grdDataView_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdDataView.CellContentClick
End Sub
Private Sub grpNavigation_Enter(sender As System.Object, e As System.EventArgs) Handles grpNavigation.Enter
End Sub
End Class
Thank you!