I've made a stored procedure in SQL server 2008, however, when i try to use in it C# (visual studio), it returns no rows (he doesn't return anything).
The Connection string is correct becouse,
This works:
SqlConnection connection = new SqlConnection("Data Source=LT004512\\SQLEXPRESS;Initial Catalog=TestDatabase;Integrated Security=SSPI;");
SqlCommand command = new SqlCommand();
DataTable data = new DataTable();
command.CommandText = "SELECT * FROM item WHERE item_ID = @hoi";
command.Connection = connection;
command.Parameters.AddWithValue("@hoi", 1);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
data.Load(reader);
connection.Close();
DeGridView.DataSource = data;
but THIS doesn't:
SqlConnection connection = new SqlConnection("Data Source=LT004512\\SQLEXPRESS;Initial Catalog=TestDatabase;Integrated Security=SSPI;");
SqlCommand command = new SqlCommand("usp_GetItemWithID",connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
command.Parameters.AddWithValue("@hetid", 1);
DataTable InstellingTabel = new DataTable();
SqlDataReader informatie = command.ExecuteReader();
connection.Close();
InstellingTabel.Load(informatie);
DeGridView.DataSource = InstellingTabel;
My stored procedure looks like this:
USE [TestDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_GetItemWithID]
@hetid int
AS
SELECT * FROM item
WHERE item_ID=@hetid
But when i execute the stored procedure in SQL server it works just fine, so i think that won't be the problem.
Sorry for the S***load of information i gave, but i'm new here and unfamiliar with asking questions about this stuff.