I am brand new to .net but not to SQL.
I am using an OleDbConnection to an Oracle database and am having difficulties filling a dataset when there are multiple tables in the SQL query.
This statement poses no difficulty.
SELECT emp.firstname, emp.lastname, emp.orgid
FROM emp
WHERE emp.empid = user_name_param
This statement, selecting from two tables, is the issue.
SELECT emp.firstname, emp.lastname, emp.orgid, org.segment
FROM emp, org
WHERE emp.orgid = org.orgid
AND emp.empid = user_name_param
I must be missing something. Can any steer me in the right direction?
The complete code is :
Public Shared Function GetEmpData() As DataSet
Dim dsEmpData As New DataSet
Dim cmdEmpData As New System.Data.OleDb.OleDbCommand
Dim sessEmpId = GetSessionEmployee().empId
'Create select statment.
Dim sSelect As String = "SELECT empid, firstname, lastname, orgid FROM emp WHERE empid = ? "
'Assign the properties for our OleDB command.
cmdEmpData.CommandText = sSelect
cmdEmpData.Connection = Connection()
cmdEmpData.Parameters.Add("?", OleDbType.Char, 9).Value = sessEmpId
Dim mysql As String = sSelect
'Create an Ole DB Adapter.
Dim daEmpData As New System.Data.OleDb.OleDbDataAdapter
'Assign values to our Data Adapter properties.
daEmpData.SelectCommand = cmdEmpData
daEmpData.MissingSchemaAction = MissingSchemaAction.AddWithKey
'Execute the stament and fill our Data Set with the result set.
daEmpData.Fill(dsEmpData, "EmpDataTable")
Return dsEmpData
End function
I am using an OleDbConnection to an Oracle database and am having difficulties filling a dataset when there are multiple tables in the SQL query.
This statement poses no difficulty.
SELECT emp.firstname, emp.lastname, emp.orgid
FROM emp
WHERE emp.empid = user_name_param
This statement, selecting from two tables, is the issue.
SELECT emp.firstname, emp.lastname, emp.orgid, org.segment
FROM emp, org
WHERE emp.orgid = org.orgid
AND emp.empid = user_name_param
I must be missing something. Can any steer me in the right direction?
The complete code is :
Public Shared Function GetEmpData() As DataSet
Dim dsEmpData As New DataSet
Dim cmdEmpData As New System.Data.OleDb.OleDbCommand
Dim sessEmpId = GetSessionEmployee().empId
'Create select statment.
Dim sSelect As String = "SELECT empid, firstname, lastname, orgid FROM emp WHERE empid = ? "
'Assign the properties for our OleDB command.
cmdEmpData.CommandText = sSelect
cmdEmpData.Connection = Connection()
cmdEmpData.Parameters.Add("?", OleDbType.Char, 9).Value = sessEmpId
Dim mysql As String = sSelect
'Create an Ole DB Adapter.
Dim daEmpData As New System.Data.OleDb.OleDbDataAdapter
'Assign values to our Data Adapter properties.
daEmpData.SelectCommand = cmdEmpData
daEmpData.MissingSchemaAction = MissingSchemaAction.AddWithKey
'Execute the stament and fill our Data Set with the result set.
daEmpData.Fill(dsEmpData, "EmpDataTable")
Return dsEmpData
End function