I am trying to use SqlDataAdapter to execute a Stored
Procedure.
The Stored Procedure is as follows
CREATE Procedure SP_GetAddressesFromContactID
@ID int
AS
SELECT
b.StreetAddress1,
b.StreetAddress2,
b.StreetAddress3,
b.Town,
b.PostCode,
b.County,
b.Status
FROM
Names a,
Addresses b,
Add_Ref c
WHERE
a.ID = c.Name_ID
AND
b.ID = c.Address_ID
AND
a.ID = @ID
RETURN
GO
The code to execute his stored procedure is as follows
DataSet ds = new DataSet("AddressesFromContact");
// Create a SqlDataAdapter.
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand sqlNamesCmd = new SqlCommand
("SP_GetAddressesFromContactID", _sqlConn);
// Add Parameters to SPROC
SqlParameter prmID = new SqlParameter("@ID",
SqlDbType.Int, 4);
prmID.Value = id;
sqlNamesCmd.Parameters.Add(prmID);
myAdapter.SelectCommand = sqlNamesCmd;
myAdapter.Fill(ds);
return ds;
When I run this code in ASP.NET I get the following error
Line 1: Incorrect syntax
near 'SP_GetAddressesFromContactID'.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException:
Line 1: Incorrect syntax
near 'SP_GetAddressesFromContactID'.
Source Error:
Line 562:
Line 563: myAdapter.SelectCommand = sqlNamesCmd;
Line 564: myAdapter.Fill(ds);
Source File:
c:\inetpub\wwwroot\contactsandorganisationsservice \service
1.asmx.cs Line: 564
Can anyone help please??? 3 12693
Hi,
Set the command type to StoredProcedure as in sqlNamesCmd.CommandType =
CommandType.StoredProcedure; before doing the Fill.
"W Akthar" <an*******@discussions.microsoft.com> wrote in message
news:2b****************************@phx.gbl...
I am trying to use SqlDataAdapter to execute a Stored
Procedure.
The Stored Procedure is as follows
CREATE Procedure SP_GetAddressesFromContactID
@ID int
AS
SELECT
b.StreetAddress1,
b.StreetAddress2,
b.StreetAddress3,
b.Town,
b.PostCode,
b.County,
b.Status
FROM
Names a,
Addresses b,
Add_Ref c
WHERE
a.ID = c.Name_ID
AND
b.ID = c.Address_ID
AND
a.ID = @ID
RETURN
GO
The code to execute his stored procedure is as follows
DataSet ds = new DataSet("AddressesFromContact");
// Create a SqlDataAdapter.
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand sqlNamesCmd = new SqlCommand
("SP_GetAddressesFromContactID", _sqlConn);
// Add Parameters to SPROC
SqlParameter prmID = new SqlParameter("@ID",
SqlDbType.Int, 4);
prmID.Value = id;
sqlNamesCmd.Parameters.Add(prmID);
myAdapter.SelectCommand = sqlNamesCmd;
myAdapter.Fill(ds);
return ds;
When I run this code in ASP.NET I get the following error
Line 1: Incorrect syntax
near 'SP_GetAddressesFromContactID'.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException:
Line 1: Incorrect syntax
near 'SP_GetAddressesFromContactID'.
Source Error:
Line 562:
Line 563: myAdapter.SelectCommand = sqlNamesCmd;
Line 564: myAdapter.Fill(ds);
Source File:
c:\inetpub\wwwroot\contactsandorganisationsservice \service
1.asmx.cs Line: 564
Can anyone help please???
Hi,
For the start, try setting:
sqlNamesCmd.CommandType = CommandType.StoredProcedure;
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com www.rthand.com
"W Akthar" <an*******@discussions.microsoft.com> wrote in message
news:2b****************************@phx.gbl... I am trying to use SqlDataAdapter to execute a Stored Procedure.
The Stored Procedure is as follows
CREATE Procedure SP_GetAddressesFromContactID @ID int AS SELECT b.StreetAddress1, b.StreetAddress2, b.StreetAddress3, b.Town, b.PostCode, b.County, b.Status FROM Names a, Addresses b, Add_Ref c WHERE a.ID = c.Name_ID AND b.ID = c.Address_ID AND a.ID = @ID RETURN GO
The code to execute his stored procedure is as follows
DataSet ds = new DataSet("AddressesFromContact"); // Create a SqlDataAdapter. SqlDataAdapter myAdapter = new SqlDataAdapter(); SqlCommand sqlNamesCmd = new SqlCommand ("SP_GetAddressesFromContactID", _sqlConn); // Add Parameters to SPROC SqlParameter prmID = new SqlParameter("@ID", SqlDbType.Int, 4); prmID.Value = id; sqlNamesCmd.Parameters.Add(prmID);
myAdapter.SelectCommand = sqlNamesCmd; myAdapter.Fill(ds);
return ds;
When I run this code in ASP.NET I get the following error
Line 1: Incorrect syntax near 'SP_GetAddressesFromContactID'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'SP_GetAddressesFromContactID'.
Source Error:
Line 562: Line 563: myAdapter.SelectCommand = sqlNamesCmd; Line 564: myAdapter.Fill(ds);
Source File: c:\inetpub\wwwroot\contactsandorganisationsservice \service 1.asmx.cs Line: 564 Can anyone help please???
Brilliant!!
Thanks! -----Original Message----- Hi,
Set the command type to StoredProcedure as in
sqlNamesCmd.CommandType =CommandType.StoredProcedure; before doing the Fill.
"W Akthar" <an*******@discussions.microsoft.com> wrote
in messagenews:2b****************************@phx.gbl... I am trying to use SqlDataAdapter to execute a Stored Procedure.
The Stored Procedure is as follows
CREATE Procedure SP_GetAddressesFromContactID @ID int AS SELECT b.StreetAddress1, b.StreetAddress2, b.StreetAddress3, b.Town, b.PostCode, b.County, b.Status FROM Names a, Addresses b, Add_Ref c WHERE a.ID = c.Name_ID AND b.ID = c.Address_ID AND a.ID = @ID RETURN GO
The code to execute his stored procedure is as follows
DataSet ds = new DataSet("AddressesFromContact"); // Create a SqlDataAdapter. SqlDataAdapter myAdapter = new SqlDataAdapter(); SqlCommand sqlNamesCmd = new SqlCommand ("SP_GetAddressesFromContactID", _sqlConn); // Add Parameters to SPROC SqlParameter prmID = new SqlParameter("@ID", SqlDbType.Int, 4); prmID.Value = id; sqlNamesCmd.Parameters.Add(prmID);
myAdapter.SelectCommand = sqlNamesCmd; myAdapter.Fill(ds);
return ds;
When I run this code in ASP.NET I get the following error
Line 1: Incorrect syntax near 'SP_GetAddressesFromContactID'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'SP_GetAddressesFromContactID'.
Source Error:
Line 562: Line 563: myAdapter.SelectCommand = sqlNamesCmd; Line 564: myAdapter.Fill(ds);
Source File: c:\inetpub\wwwroot\contactsandorganisationsservic e\servic
e1.asmx.cs Line: 564 Can anyone help please???
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bill Priess |
last post by:
Hey gang,
Ok, I'm stumped on this one... I am using the using statement to wrap a
SqlDataAdapter that I am using to fill a DataTable. Now, what I need to know
is, just how much block-scope...
|
by: goodstart123 |
last post by:
For example, the following code works fine without SqlConnection.
Any Answer to the question?
string connectionString =
"server=YourServer; uid=sa;
pwd=YourPassword;...
|
by: Khurram |
last post by:
Hi,
I am trying to use Crystal Reports with ASP.NET. I created a dataset
and tried to display it in the report but nothing came up. I did not
get an exception either. I know that the dataset is...
|
by: Mike Hutton |
last post by:
I have a rather odd problem.
I have a SP which uses temp. tables along the way, and then returns a
table of results:
CREATE PROCEDURE dbo.usp_myproc(
@pNameList VARCHAR(6000)
)
AS
|
by: Spencer H. Prue |
last post by:
Hello!,
I have a using system.web.sessionstate directive one the top of each of two
web pages. On the first page I have the dataadapter, dataconnection, and
dataset (also in the component tray)....
|
by: koonda |
last post by:
Hi guys,
I posted a message before and I got some help from the forum. I have a database in SQL Server and I wanted to create a web interface in C#. I had 4 Listbox controls and a Textbox and two...
|
by: Simon |
last post by:
Hi all,
I'm having a baffling problem with a windows service that I'm working on.
Basically, I am using a typed dataset to insert a large number of rows
into an SQL Server 2005 database. But...
|
by: TonyJ |
last post by:
Hello!
I trying to update a table using sql server but no update will be done.
I don't get any error at all.
Here is an extract from the code. Does this seems to be right.
|
by: MrMancunian |
last post by:
How to create a database connection without using wizards
Introduction
I've seen a lot of questions on the net about getting data from, and saving data to databases. Here's a little insight how...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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: 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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |