473,655 Members | 3,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1526
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" <jamesATnorto n-associates.co.u kREMOVE> wrote in message
news:eo******** ******@tk2msftn gp13.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
1253
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 column to move to 2. i bind my datagrid with a stored procedure from my sql database (by using dataadapter,dataset ...) and i need to send a parameter to the stored procedure, how can i do it? the wizard that opens when i drag the dataadapter...
0
2203
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 beating upon myself !!!!!!!!!!!! TABLE SCRIPT
1
2076
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. I call an update method of adapter. But how to pass the parameters from DataGrid to commands? They must fill automatically by some way? If I set parameters of commands mannually - it works fine.
6
1612
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 (i.e. CA for Calif), the datagrids header is displayed when the button is clicked, but no data is displayed. I used SQL Profiler and can see that the query comes across with the parameter, and if I take that query string and use it exactly in Query...
0
1101
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: ------------------- Public Class WebForm1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code "
2
267
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 with no problem. My question is no I want the underlaying sql statement to be able to be based on a variable. In other words my sql statement is: select * from tblCustomers where CustKey = 1. I would like to set up a interager variable intI and...
4
1729
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 at my code segments and provide any insight in a reply, I would be eternally grateful. My table name is "rfi" and the field with a dropdownlist control is called "contract". I have imported the System.Data and System.Data.OleDb libraries. ...
5
2870
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 table, which is working fine inside the programming, and in the database. However, I still cannot figure out what am I doing wrong with the DataGrid configurations OR Database OR DataAdapter OR SqlSelectCommand ... I really don't know yet and I...
0
1766
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 the parameter. I have another procedure which adds another row to the table, which is working fine inside the programming, and in the database. However, I still cannot figure out what am I doing wrong with the DataGrid configurations OR...
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.