Tom Powers
asked on
Get lastname from database and populate textboxes no binding
I wrote a form in which you enter lastname and then should return data and populate textboxes I know that I created a sub that grab's lastname but I don't know how to return that dataset into a new function
here is what I wrote
here is what I wrote
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports System.Data.SqlDbType
Public Class LastnameSelectNCCA
Public sql As String
Public ds As New DataSet
Public stgnccapath As String = "\\tsnfps01\webdev\branding\tompowers\College Football logos\"
Public connetionString As String
Public connection As SqlConnection
Public adapter As SqlDataAdapter
Public objDataReader As SqlDataReader
Public SelectCommand As New SqlCommand
Public intLast As Integer
Public Sub GetNccaplayers()
connetionString = "Data Source=tsnappdev01;Initial Catalog=TSN2;User ID=sa;Password=XXXXXXXXX"
connection = New SqlConnection(connetionString)
sql = "SELECT FirstName, LastName,Position,College,Class,TeamID,PlayerID"
sql += " FROM NCAA_FB_PLAYERS WHERE"
sql += " STATUS ='A' AND FIRSTNAME <>'Team' AND Lastname like '%" & _
txtLastname.Text & "%'" & "ORDER BY LastName DESC"
Try
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.SelectCommand.Parameters.AddWithValue("@Lastname", txtLastname.Text)
adapter.Fill(ds)
connection.Close()
Catch ex As SqlException
MsgBox(ex.ToString)
End Try
LoadData()
End Sub
Public Sub LoadData()
connetionString = "Data Source=tsnappdev01;Initial Catalog=TSN2;User ID=sa;Password=sportsrus"
connection = New SqlConnection(connetionString)
Dim intLast As Integer = txtPlayerID.Text
Try
Dim SqlCommand = New SqlCommand
Dim objCommand = New SqlCommand
'Set the objCommand object properties
objCommand.CommandText = "SelectID"
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Connection = connection
'Add the required parameter for the query
' objCommand.Parameters.Add("@ID", OleDbType.Guid, 16).Value = _
' New Guid(ComboBox1.SelectedValue.ToString)
objCommand.Parameters.Add("@PlayerID", SqlDbType.Int, 32).Value = CInt(intLast)
Dim objDataReader As SqlDataReader
'Execute the Query
objDataReader = objCommand.ExecuteReader()
'If we have data then display the project description
If objDataReader.HasRows Then
objDataReader.Read()
txtFirst.Text = objDataReader.Item("Firstname")
txtLast.Text = objDataReader.Item("Lastname")
Position.Text = objDataReader.Item("Position")
txtCollege.Text = objDataReader.Item("College")
txtClass.Text = objDataReader.Item("Class")
txtTeamID.Text = objDataReader.Item("TeamID")
txtPlayerID.Text = objDataReader.Item("PlayerID")
End If
Catch sqlExceptionErr As SqlException
MessageBox.Show(sqlExceptionErr.Message)
End Try
objDataReader.Close()
connection.Close()
End Sub
Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
Me.Close()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
picNCAATeam.ImageLocation = stgnccapath & txtTeamID.Text & ".jpg"
End Sub
Private Sub btnselectLastname_Click(sender As Object, e As EventArgs) Handles btnselectLastname.Click
If txtLast.Text = "" Then
Exit Sub
Else
GetNccaplayers()
End If
End Sub
End Class
Thanks EE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER