473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

No Results in Datatable

If have a stored procedure that seems to work fine through query analyzer
but if I attempt the same thing via code, no exceptions are thrown but no
results are ever returned. I'm using the ODBC.NET dataprovider.

The string that I cut and paste when I debug is:

sp_OrgChart 1900,
'''ANALYS'',''ARLDR'',''DLDR'',''ENG'',''PROG'','' STU'',''DLDR'''

and again, this works great in query analyzer.

However, the following code never returns any results. The SQL statement
argument would look like the string above. I've left out the error handling
etc. It works great for regular SQL statements though.

Public Function ReturnDataTable(ByVal SQLStatement As String, ByVal
InsertRowAtIndex0 As Boolean) As DataTable

Dim myConnection As OdbcConnection
Dim myCommand As OdbcCommand
Dim myDA As OdbcDataAdapter

myConnection = New OdbcConnection(strConnectionString)
myCommand = New OdbcCommand(SQLStatement, myConnection)
myDA = New OdbcDataAdapter
myDA.SelectCommand = myCommand

Dim myDT As New DataTable

Try
m_GeneralError = ""
myDA.Fill(myDT)

If InsertRowAtIndex0 Then
Dim BlankRow As System.Data.DataRow = myDT.NewRow()
myDT.Rows.InsertAt(BlankRow, 0)
End If
Return myDT

catch Ex as Exception

End try

End Function
And here is my stored procedure:
CREATE PROCEDURE sp_OrgChart

@Department int,
@JobCodes nvarchar(500)

AS
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[OrgChartTemp]') and OBJECTPROPERTY(id, N'IsUserTable') =
1)
drop table [dbo].[OrgChartTemp]

declare @TableName as nvarchar(50)
declare @TempQuery as nchar(2500)
SELECT * INTO dbo.OrgChartTemp FROM vw_OrgChartReportsTo WHERE DepartmentID
= @Department
DECLARE @DepartmentLeaderCount int
SET @DepartmentLeaderCount = (SELECT COUNT(*) FROM dbo.OrgChartTemp WHERE
JobCode = 'DLDR')
if @DepartmentLeaderCount = 0

begin
INSERT INTO OrgChartTemp

SELECT * FROM vw_OrgChartReportsTo WHERE JobCode = 'DLDR' AND LastName IN
(SELECT SUBSTRING(ReportsTo, 1, CHARINDEX(',', ReportsTo) - 1) FROM
OrgChartTemp)

UPDATE OrgChartTemp SET DepartmentID = (SELECT TOP 1 DepartmentID FROM
vw_OrgChartReportsTo WHERE DepartmentID = @Department), Department = (SELECT
TOP 1 Department FROM vw_OrgChartReportsTo WHERE DepartmentID = @Department)
end

exec('SELECT eeEENum, Name, ReportsTo, ImagePath, Department, Position,
Location FROM dbo.OrgChartTemp WHERE JobCode IN (' + @JobCodes + ')')
GO
Nov 17 '05 #1
0 1075

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: scott | last post by:
Hi all, Iv got a slight problem with a datagrid and the ability to only display certain things in it. I have a Data grid which is connected to a data table. The data table is connected...
1
by: Don | last post by:
I am new to Indexing Services, have been researching the MS Site as well as web articles on DevHood, etc. I have set up a seperate catalog ("KnowledgeBase") on Win XP with a number of files. I am...
4
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to...
2
by: Sandy | last post by:
Hello - I have the following stored procedure and code. I want to put the results in two textboxes. I get to the part where I create the dataset and then I don't know what to do. I tried...
2
by: Matt Michael | last post by:
I'm using ADO .NET to connect to a Microsoft Access database, and everything so far has been working in my program except one small problem. I am constructing a query string to search for certain...
2
by: Stef | last post by:
Hi people, I'd like to know if it's possible to get DataRows containing data from different tables that are part of one single dataset? Example: Dim ds As New DataSet("myDataSet") 'Load 3...
1
by: VB Programmer | last post by:
I have a SqlDataSource I setup on an ASP.NET 2.0 webform. I setup the SELECT statement and it has 1 parameter, @ProductId. How do I, using VB.NET, store the results of that SELECT statement...
9
by: Rick | last post by:
VB.Net 2005 I have a Firebird DB query that returns an XML file in its rows. I want to execute this query and write the results (rows) to a file. I am using DataTables and TableAdapters. ...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.