473,320 Members | 1,831 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,320 software developers and data experts.

DataGrid, DataAdapter, SP Parameters?

I have an sp with paramaters like this:
ALTER PROCEDURE dbo.SomeProc
(
@SortBy varchar(50) = NULL
@ShowComplete bit = 0
@StaffID int = NULL
)
AS
DECLARE @SQL varchar(2500)
SET @SQL =
'SELECT StaffID, Status FROM SomeTable '

IF @StaffID IS NOT NULL
SET @SQL = @SQL + ' WHERE StaffID = ' + @StaffID
ELSE
SET @SQL = @SQL + ' WHERE SQLLogin = SUSER_SNAME() '
IF @ShowComplete <> 1
SET @SQL = @SQL + ' AND StatusID NOT IN(3,4,5) '
IF @SortBy IS NOT NULL
SET @SQL = @SQL + ' ORDER BY ' + @SortBy

--PRINT @SQL
EXEC (@SQL)

I am trying to create a dataadapter (daTasks) bound to this sp, & then bind
my datagrid (dgdTasks) to it.

This works perfectly, until I include the parameters in the sp. The
parameters all have default values, but when I add these parameters to the
parameters collection of daTasks, I get a host of errors, such as 'Failed to
get schema for this stored procedure' & 'Input string was not in correct
format.'

For information, I can execute the sp from the IDE with or without
parameters, without a problem.

Any suggestions as to how I can solve this?
--
Cheers,

James Goodman
Nov 18 '05 #1
1 1514
Hi,

Don't use sqlstring. you have a lot of errors there.
The bellow you can find my solution, but you have to make a sort in the C#
or VB.

if @showcomlete = 1
begin
SELECT StaffID, Status FROM SomeTable
where StaffID = isnull(@StaffID, StaffID )
and SQLLogin =
case
when @StaffID is null then SUSER_SNAME()
else SQLLogin
end
end
else
begin
SELECT StaffID, Status FROM SomeTable
where StaffID = isnull(@StaffID, StaffID )
and SQLLogin =
case
when @StaffID is null then SUSER_SNAME()
else SQLLogin
end
end

bye

"James" <jamesATnorton-associates.co.ukREMOVE> wrote in message
news:eo**************@tk2msftngp13.phx.gbl...
I have an sp with paramaters like this:
ALTER PROCEDURE dbo.SomeProc
(
@SortBy varchar(50) = NULL
@ShowComplete bit = 0
@StaffID int = NULL
)
AS
DECLARE @SQL varchar(2500)
SET @SQL =
'SELECT StaffID, Status FROM SomeTable '

IF @StaffID IS NOT NULL
SET @SQL = @SQL + ' WHERE StaffID = ' + @StaffID
ELSE
SET @SQL = @SQL + ' WHERE SQLLogin = SUSER_SNAME() '
IF @ShowComplete <> 1
SET @SQL = @SQL + ' AND StatusID NOT IN(3,4,5) '
IF @SortBy IS NOT NULL
SET @SQL = @SQL + ' ORDER BY ' + @SortBy

--PRINT @SQL
EXEC (@SQL)

I am trying to create a dataadapter (daTasks) bound to this sp, & then bind my datagrid (dgdTasks) to it.

This works perfectly, until I include the parameters in the sp. The
parameters all have default values, but when I add these parameters to the
parameters collection of daTasks, I get a host of errors, such as 'Failed to get schema for this stored procedure' & 'Input string was not in correct
format.'

For information, I can execute the sp from the IDE with or without
parameters, without a problem.

Any suggestions as to how I can solve this?
--
Cheers,

James Goodman

Nov 18 '05 #2

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

Similar topics

1
by: Gidi | last post by:
helo i have few questions about working with datagrid 1. after i got help from this forum i succeded to move between columns by preesing the enter key, now my questio is how can i decdied which...
0
by: Christopher | last post by:
I AM GETTING A SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION ERROR WHEN ATTEMPTING TO INSERT DATA INTO A SINGLE TABLE THROUGH A GRID //If this is due to a spelling error, i will //inflict a ritual...
1
by: Eugene Turin | last post by:
I'm writing a simple app that acts with simple DBF table via ODBCAdapter. I've got the idea of working with DataGrid, DataDet and DataAdapter. I connect to my Adapter DeleteCommand and AddComand....
6
by: JeffB | last post by:
I have tried several different methods of getting a datagrid to fill with information. Below is the code I'm now using. When viewed in the browser and the text box filled with a parameter value...
0
by: John Hopper | last post by:
Can someone please tell me why the datagrid doesn't databind and display rows once the Add button is clicked and the cmdSaveToDataset event fires, to add a row to the dataset? I've copied the code:...
2
by: Channa | last post by:
I have a datagrid that is bound to an MSDataSetGenerator that is then bound to an access database though a OleDbDataAdapter and an OleDbConnection. I am able to open the form and its datagrid...
4
by: glenn | last post by:
Hi folks, I am getting an error "Object reference not set to an instance of an object". It seems I have everything in place but something is obviously in err. If you could take a quick peak...
5
nmm32
by: nmm32 | last post by:
I have a DataGrid which displays data with the aid of a procedure. I have tested the procedure inside the database and it is working fine. I have another procedure which adds another row to the...
0
by: cms3023 | last post by:
I have a DataGrid which displays data with the aid of a procedure. I have tested the procedure inside the database and it is working fine. The table inside the database has data that matches with...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.