First, thanks for your help and patience.
I understand what the error " ‘<<<receive error message “Value of type System.Data.DataSet cannot be converted to String” is telling me. I do not understand
why it is telling me this.
I thought that the function GetData was supposed to retrieve the data requested by the SQL string “MyStrName = ("select LastName, FirstName from tbl_ClntBasicInfo where ClientNumber=1000")” and convert the returned data to a data set.
Once the data is retrieved, it would be placed in the dataset that has been declared in the line “Dim MyDSName As DataSet = New DataSet("Last and First Name")” using the line “MyDSName = get_data(MyStrName)”
-------
I will be returning a bunch of information: Names, address, city, state, zip, pay rates, vacation balance, etc. from various tables that are related by the PK “ClientNumber”. In the situation of Client Info, I will want the info to be displayed in text boxes on a form for each client when their number is entered, with the exception being History records once I get things going, which will show multiple pay periods for the client.
There will also be some job info, but the process/display of info I believe will be similar to the Client info.
There will be a timesheet entry form that will use both Client and Job info to calculate pay. This is not a “Hour times wage = pay” type system. It will be using piece rates per unit and other types of pay.
I was trying to start small and build on what I learned. Here’s my updated code:
Code:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.DataTableCollection
Module GetData
Public Function get_data(ByVal SqlGetData As String) As String
Dim Conn As SqlConnection = New SqlConnection("Data Source=B-7M2KXC45F9FT4\SQLEXPRESS;Initial Catalog=ClientPayroll;Trusted_Connection=yes;User Id=B-7M2KXC45F9FT4\administrator")
Dim cmd2 As New SqlCommand
Dim DA1 As SqlDataAdapter = New SqlDataAdapter(SqlGetData, Conn)
'Dim senddataback As String
Dim MYds As New DataSet
If Conn.State = ConnectionState.Closed Then Conn.Open()
With cmd2
.Connection = Conn
.CommandType = CommandType.Text
.CommandText = (SqlGetData)
End With
'senddataback = cmd2.ExecuteScalar
DA1.Fill(MYds, "tbl_ClntBasicInfo")
Conn.Dispose()
cmd2.Dispose()
Return MYds
End Function
End Module
‘---------------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.DataTableCollection
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyStrName As String
'Dim MyDataName As DataSet
Dim LastName As String
Dim FirstName As String
Dim MyDSName As DataSet = New DataSet("Last and First Name")
MyStrName = ("select LastName, FirstName from tbl_ClntBasicInfo where ClientNumber=1000")
' MyDataName = get_data(MyStrName)
'MyDSName = get_data(MyStrName)
MyDSName = get_data(MyStrName)
LastName = MyDSName.Tables("tbl_ClntBasicInfo").Rows(0).Item(1)
FirstName = MyDSName.Tables("tbl_ClntBasicInfo").Rows(0).Item(2)
End Sub
End Class
‘---------------------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.DataTableCollection
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyStrWage As String
'Dim MyDataWage As String
Dim Avg As String
Dim Fringe As String
Dim MyDSWage As DataSet = New DataSet("Wage Rates")
MyStrWage = ("select average, fringe from tbl_ClntPayRates where userid=1000")
'MyDataWage = get_data(MyStrWage)
MyDSWage = get_data(MyStrWage)
Avg = MyDSWage.Tables("tbl_ClntPayRates").Rows(0).Item(1)
Fringe = MyDSWage.Tables("tbl_ClntPayRates").Rows(0).Item(2)
‘going to display in text boxes, not a message box
‘ MessageBox.Show("Average wage is " & Avg & " Fringe is " & Fringe)
End Sub
End Class
Since I am wanting infor in text boxes, using the dataadapter, shouldn’t I have text boxes and code on my forms such as:
Code:
Private sub ShowClientInformation ()
If m_dsClients.Rows.Count = 0 then
txtLastName.text = “”
txtFirstName.text = “”
Exit Sub
End If
txtLastName.text = m_dsClients.Rows(m_rowPosition)(“LastName”).ToString()
txtFirstName.text = m_dsClients.Rows(m_rowPosition)(“FirstName”).ToString()
End Sub
I’m pulling the above from the book “Sam’s Teach Yourself VB 2005”
Thanks.