I am trying to write a code for correction of entries to my SQL Server database. I am a mechanical engineering student who has a programming class and I have never programmed before so I am not sure should I convert string to decimal and how. Last 2 rows contain 2 options I came up with. Second one is what I use for pure string, first one is a modification of formatting datetime.
This is my stored procedure:
ALTER PROCEDURE [dbo].[SP_RN_O_Ispravak]
@Br_RN_O bigint,
@Datum_O DateTime OUTPUT,
@Sifra_p int OUTPUT,
@Ime_P nvarchar (30) output,
@Prezime_P NVarChar(30) OUTPUT,
@Naziv_P nvarchar (50) output,
@Adresa_P nvarchar (50) OUTPUT,
@Telefon_P NVarChar(15) OUTPUT,
@Sifra_z int OUTPUT,
@Ime_Z nvarchar (30) output,
@Prezime_Z nvarchar (30) output,
@Sifra_kul nvarchar (3) OUTPUT,
@Naziv_Kul NVarChar(20) OUTPUT,
@Masa_O decimal (5,0) OUTPUT,
@Vlaga_O decimal (4,1) OUTPUT,
@Hek_Masa_O decimal (3,1) OUTPUT,
@Protein_O decimal (3,1) output,
@Cijena_O decimal (3,2) output
AS
SELECT @Br_RN_O=T_Otkup.Br_RN_O,
@Datum_O=T_Otkup.Datum_O,
@Sifra_p=T_Otkup.Sifra_p,
@Sifra_z=T_Otkup.Sifra_z,
@Sifra_kul=T_Otkup.Sifra_kul,
@Masa_O=T_Otkup.Masa_O,
@Vlaga_O=T_Otkup.Vlaga_O,
@Hek_Masa_O=T_Otkup.Hek_Masa_O,
@Protein_O=T_Otkup.Protein_O
FROM T_Otkup
WHERE (T_Otkup.Br_RN_O = @Br_RN_O)
SELECT @Prezime_P=Prezime_P
FROM T_Poljoprivrednik
WHERE Sifra_P=@Sifra_p
SELECT @Prezime_z=Prezime_Z
FROM T_Zaposlenik
WHERE Sifra_Z=@Sifra_z
SELECT @Naziv_kul=Naziv_Kul
FROM T_Kultura
WHERE Sifra_Kul=@Sifra_kul
RETURN
This procedure is supposed to pull the data from the database and place it in textboxes shown in the image.visual of whati'm trying to make I managed to use the following code to convert decimal to string:
Dim cijenao As SqlParameter = New SqlParameter("@Cijena_O", Data.SqlDbType.Decimal, 3, 2)
cijenao.Direction = Data.ParameterDirection.Output
cijenao.Value = Cijena_O.Text
cmd.Parameters.Add(cijenao)
Masa_O.Text = Format(masao.Value, "#####").ToString
Vlaga_O.Text = Format(vlagao.Value, "###.#").ToString
Hek_Masa_O.Text = Format(hmasao.Value, "##.#").ToString
Protein_O.Text = Format(proto.Value, "##.#").ToString
However, it doesn't work for 2 decimal places like this:
Cijena_O.Text = Format(cijenao.Value, "#.##").ToString
I tried using the code posted by Mary, but it get the following message:
System.Data.SqlClient.SqlException: 'Procedure or function SP_RN_O_Ispravak has too many arguments specified.'