[c#] problem with calling stored procedure

P

Piotrek \Alchemik\

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.SelectedValue),
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
 
?

=?ISO-8859-2?Q?G=F6ran_Andersson?=

Standard question #1:
What do you mean by "not working"?

Standard question #2:
What error message do you get?
 
Joined
Mar 20, 2008
Messages
1
Reaction score
0
The Reason

Hello,
This is Rohit.
The reason for you not getting the output might be real simple. lets see.

You know that it is a stored procedure you are calling, and we know it is, because you told us, but the compiler doesn't know. So why don't you let it know.

Use the following statement after you have instantiated the command object.
command.CommandType = CommandType.StoredProcedure;

Hope you got the solutions.
If you still have problems, mail me at
(e-mail address removed)

Have a nice day
Rohit Srinivasan Mudambi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top