Protschj
Gebruiker
- Lid geworden
- 22 nov 2006
- Berichten
- 15
I will get an id from my stored procedure so I can work with it in Visual Studio. My stored procedure looks like :
USE [topdesk]
GO
/****** Object: StoredProcedure [dbo].[sp_AddEstablishment] Script Date: 06/04/2008 21:25:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Inge Leenders
-- Create date: Woensdag, 14 mei 2008.
-- Description: Vestiging toevoegen.
-- =============================================
ALTER PROCEDURE [dbo].[sp_AddEstablishment]
@dataanmk datetime,
@datwijzig datetime,
@email nvarchar(100),
@fax nvarchar(25),
@huisnummer1 nvarchar(7),
@naam nvarchar(60),
@plaats1 nvarchar(30),
@postcode1 nvarchar(15),
@ref_kleur int,
@status int,
@straat1 nvarchar(50),
@telefoon nvarchar(25),
@website nvarchar(100),
@outputID nchar(6) OUT
AS
DECLARE @unid nchar(6)
SET @unid = dbo.CreateIDForEstablishment()
SET @outputID = @unid
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO dbo.vestiging(unid, dataanmk, datwijzig, email, fax, huisnummer1,
naam, plaats1, postcode1, ref_kleur, [status], straat1, telefoon, website)
VALUES (@unid, @dataanmk, @datwijzig, @email, @fax, @huisnummer1,
@naam, @plaats1, @postcode1, @ref_kleur, @status, @straat1, @telefoon, @website)
END
The code looks like :
com.Connection = conn;
com.CommandText = "sp_AddEstablishment";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@dataanmk", this.Dataanmk);
com.Parameters.AddWithValue("@datwijzig", this.Datwijzig);
com.Parameters.AddWithValue("@email", this.Email);
com.Parameters.AddWithValue("@fax", this.Fax);
com.Parameters.AddWithValue("@huisnummer1", this.Huisnummer1);
com.Parameters.AddWithValue("@naam", this.Naam);
com.Parameters.AddWithValue("@plaats1", this.Plaats1);
com.Parameters.AddWithValue("@postcode1", this.Postcode1);
com.Parameters.AddWithValue("@ref_kleur", this.Ref_kleur);
com.Parameters.AddWithValue("@status", this.Status);
com.Parameters.AddWithValue("@straat1", this.Straat1);
com.Parameters.AddWithValue("@telefoon", this.Telefoon);
com.Parameters.AddWithValue("@website", this.Website);
com.Parameters.Add("@outputID", SqlDbType.NChar);
com.Parameters["@outputID"].Direction = ParameterDirection.Output;
Console.WriteLine("Voor de execute query");
com.ExecuteNonQuery();
Console.WriteLine("Na de execute query");
vestigingUnid = (string)com.Parameters["@outputID"].Value;
Console.WriteLine("VestigingUnid =" + vestigingUnid);
Console.WriteLine("Insert Vestiging gelukt");
I get this error :
String[13]: the Size property has an invalid size of 0.
Can someone help me please ?
Greetz, Inge
USE [topdesk]
GO
/****** Object: StoredProcedure [dbo].[sp_AddEstablishment] Script Date: 06/04/2008 21:25:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Inge Leenders
-- Create date: Woensdag, 14 mei 2008.
-- Description: Vestiging toevoegen.
-- =============================================
ALTER PROCEDURE [dbo].[sp_AddEstablishment]
@dataanmk datetime,
@datwijzig datetime,
@email nvarchar(100),
@fax nvarchar(25),
@huisnummer1 nvarchar(7),
@naam nvarchar(60),
@plaats1 nvarchar(30),
@postcode1 nvarchar(15),
@ref_kleur int,
@status int,
@straat1 nvarchar(50),
@telefoon nvarchar(25),
@website nvarchar(100),
@outputID nchar(6) OUT
AS
DECLARE @unid nchar(6)
SET @unid = dbo.CreateIDForEstablishment()
SET @outputID = @unid
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO dbo.vestiging(unid, dataanmk, datwijzig, email, fax, huisnummer1,
naam, plaats1, postcode1, ref_kleur, [status], straat1, telefoon, website)
VALUES (@unid, @dataanmk, @datwijzig, @email, @fax, @huisnummer1,
@naam, @plaats1, @postcode1, @ref_kleur, @status, @straat1, @telefoon, @website)
END
The code looks like :
com.Connection = conn;
com.CommandText = "sp_AddEstablishment";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@dataanmk", this.Dataanmk);
com.Parameters.AddWithValue("@datwijzig", this.Datwijzig);
com.Parameters.AddWithValue("@email", this.Email);
com.Parameters.AddWithValue("@fax", this.Fax);
com.Parameters.AddWithValue("@huisnummer1", this.Huisnummer1);
com.Parameters.AddWithValue("@naam", this.Naam);
com.Parameters.AddWithValue("@plaats1", this.Plaats1);
com.Parameters.AddWithValue("@postcode1", this.Postcode1);
com.Parameters.AddWithValue("@ref_kleur", this.Ref_kleur);
com.Parameters.AddWithValue("@status", this.Status);
com.Parameters.AddWithValue("@straat1", this.Straat1);
com.Parameters.AddWithValue("@telefoon", this.Telefoon);
com.Parameters.AddWithValue("@website", this.Website);
com.Parameters.Add("@outputID", SqlDbType.NChar);
com.Parameters["@outputID"].Direction = ParameterDirection.Output;
Console.WriteLine("Voor de execute query");
com.ExecuteNonQuery();
Console.WriteLine("Na de execute query");
vestigingUnid = (string)com.Parameters["@outputID"].Value;
Console.WriteLine("VestigingUnid =" + vestigingUnid);
Console.WriteLine("Insert Vestiging gelukt");
I get this error :
String[13]: the Size property has an invalid size of 0.
Can someone help me please ?
Greetz, Inge