473,326 Members | 2,133 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,326 software developers and data experts.

[c#] problem with calling stored procedure

Hello,

i'm trying to call stored procedure like:

ALTER PROCEDURE [dbo].[getValuesDay]
@p1 int,
@p2 Datetime
AS
BEGIN
SET NOCOUNT ON;
SELECT Value, Date FROM [testowa].[dbo].[test1]
WHERE ID_sensor = @p1 AND @p2 = Convert(nchar(10),[Date],102)
END

From ASP web page using c#. The code looks like:

string connectionString =
ConfigurationManager.ConnectionStrings["testowaConnectionString"].ConnectionString;
SqlConnection thisConnection = new
SqlConnection(connectionString);
thisConnection.Open();

SqlCommand command = new SqlCommand("getValuesDay",
thisConnection);

command.Parameters.Add("@p1", SqlDbType.Int).Value=p1;
command.Parameters.Add("@p2", SqlDbType.DateTime).Value=p2;

command.ExecuteNonQuery();

SqlDataAdapter adapter = new SqlDataAdapter(command);

DataTable dt = new DataTable();
adapter.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();
thisConnection.Close();

p1 is int and p2 is a datetime:

ReturnValues(Convert.ToInt32(showSensors.SelectedV alue),
Convert.ToDateTime(showDates.SelectedValue));

And this stored procedure is not working. When i don't hand any
parameter it's working fine. What i'm doing wrong?

Thanks in advance

Piotrek
Sep 28 '06 #1
2 2166

as a total guess.

try setting

string p2 = "12/20/2000";


"Piotrek "Alchemik"" <al**@epf.pl.spam.wonwrote in message
news:ef**********@amigo.idg.com.pl...
Hello,

i'm trying to call stored procedure like:

ALTER PROCEDURE [dbo].[getValuesDay]
@p1 int,
@p2 Datetime
AS
BEGIN
SET NOCOUNT ON;
SELECT Value, Date FROM [testowa].[dbo].[test1]
WHERE ID_sensor = @p1 AND @p2 = Convert(nchar(10),[Date],102)
END

From ASP web page using c#. The code looks like:

string connectionString =
ConfigurationManager.ConnectionStrings["testowaConnectionString"].Connection
String;
SqlConnection thisConnection = new
SqlConnection(connectionString);
thisConnection.Open();

SqlCommand command = new SqlCommand("getValuesDay",
thisConnection);

command.Parameters.Add("@p1", SqlDbType.Int).Value=p1;
command.Parameters.Add("@p2", SqlDbType.DateTime).Value=p2;

command.ExecuteNonQuery();

SqlDataAdapter adapter = new SqlDataAdapter(command);

DataTable dt = new DataTable();
adapter.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();
thisConnection.Close();

p1 is int and p2 is a datetime:

ReturnValues(Convert.ToInt32(showSensors.SelectedV alue),
Convert.ToDateTime(showDates.SelectedValue));

And this stored procedure is not working. When i don't hand any
parameter it's working fine. What i'm doing wrong?

Thanks in advance

Piotrek

Sep 28 '06 #2
Standard question #1:
What do you mean by "not working"?

Standard question #2:
What error message do you get?
Piotrek "Alchemik" wrote:
Hello,

i'm trying to call stored procedure like:

ALTER PROCEDURE [dbo].[getValuesDay]
@p1 int,
@p2 Datetime
AS
BEGIN
SET NOCOUNT ON;
SELECT Value, Date FROM [testowa].[dbo].[test1]
WHERE ID_sensor = @p1 AND @p2 = Convert(nchar(10),[Date],102)
END

From ASP web page using c#. The code looks like:

string connectionString =
ConfigurationManager.ConnectionStrings["testowaConnectionString"].ConnectionString;

SqlConnection thisConnection = new
SqlConnection(connectionString);
thisConnection.Open();

SqlCommand command = new SqlCommand("getValuesDay",
thisConnection);

command.Parameters.Add("@p1", SqlDbType.Int).Value=p1;
command.Parameters.Add("@p2", SqlDbType.DateTime).Value=p2;

command.ExecuteNonQuery();

SqlDataAdapter adapter = new SqlDataAdapter(command);

DataTable dt = new DataTable();
adapter.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();
thisConnection.Close();

p1 is int and p2 is a datetime:

ReturnValues(Convert.ToInt32(showSensors.SelectedV alue),
Convert.ToDateTime(showDates.SelectedValue));

And this stored procedure is not working. When i don't hand any
parameter it's working fine. What i'm doing wrong?

Thanks in advance

Piotrek
Sep 28 '06 #3

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

Similar topics

2
by: June Moore | last post by:
Hi all, I have a stored procedure that return a resultset e.g. stored proc: get_employee_details select emp_id, emp_name, emp_salary, emp_position from empoloyee I would like to write...
18
by: Jarrod Morrison | last post by:
Hi All I was wondering if there is a way to call a stored procedure from inside another stored procedure. So for example my first procedure will call a second stored procedure which when...
0
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access...
4
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
1
by: Raquel | last post by:
This is a stored procedure that resides on Mainframe and gets executed on the client by connecting to the mainframe through DB2 connect. It was executing fine till yesterday when I executed a table...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
3
by: Jack Black | last post by:
Help!! I'm trying to call a custom stored procedure from a VB.Net code-behind page in an ASP.Net application, and I keep getting an error with no real helpful info... Basically, I'm accepting a...
14
by: krishna1412 | last post by:
Currently i am working in a project of report generation in MS ACCESS. The tables are in sql server 2000. I have to write stored proc in ms access. Illustration: I am having a stored proc...
0
by: Big George | last post by:
Hello, I'm trying to save a jpg file of 300KB as a BLOB field in an Oracle 10g Database. If I try to call a Stored Procedure, it fails. If I use CommandText with SQL sentence, it success. I...
4
by: eighthman11 | last post by:
I'm calling a stored procedure on a sql server from an access application. I just need the stored procedure to run I do not need any data returned from the stored procedure to my Access...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.