grafzerkpisser
Legacy Member
Een klein ado.net probleempje:
Ik voorstellings gegevens uit een database halen en deze laten plaatsen in een aantal label.
Men input komt binnen via een querrystring (tot hier werkt alles degelijk).
Probleem is dat mijn output parameters niets ingevuld worden (krijgen waarde null mee) waardoor voorstellingsgegevens van de class voorstellingen niet ingevuld geraken, met als gevolg mijn labels ook niet.
Voor zover ik kan zien is mijn stored procedure ok.
Hier geeft hij dus men exception.
Wie kan mij een beetje helpen hiermee? Thnx alvast
Ik voorstellings gegevens uit een database halen en deze laten plaatsen in een aantal label.
Men input komt binnen via een querrystring (tot hier werkt alles degelijk).
Probleem is dat mijn output parameters niets ingevuld worden (krijgen waarde null mee) waardoor voorstellingsgegevens van de class voorstellingen niet ingevuld geraken, met als gevolg mijn labels ook niet.
Voor zover ik kan zien is mijn stored procedure ok.
ALTER PROCEDURE VoorstellingSpec
(
@voorstellingsNr int,
@titel nvarchar(50) OUTPUT,
@uitvoerders nvarchar(50) OUTPUT,
@datum DateTime OUTPUT,
@prijs Money output,
@vrijePlaatsen int output)
AS
select @titel=Titel, @uitvoerders = Uitvoerders, @datum = Datum, @prijs = Prijs, @vrijePlaatsen = VrijePlaatsen
from Voorstellingen
where VoorstellingsNr = @voorstellingsNr
(
@voorstellingsNr int,
@titel nvarchar(50) OUTPUT,
@uitvoerders nvarchar(50) OUTPUT,
@datum DateTime OUTPUT,
@prijs Money output,
@vrijePlaatsen int output)
AS
select @titel=Titel, @uitvoerders = Uitvoerders, @datum = Datum, @prijs = Prijs, @vrijePlaatsen = VrijePlaatsen
from Voorstellingen
where VoorstellingsNr = @voorstellingsNr
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Gemeenschappelijk
{
public class Voorstellingen
{
private Int32 voorstellingsNrValue;
private String titelValue;
private String uitvoedersValue;
private DateTime datumValue;
private Int32 genreNrValue;
private Decimal prijsValue;
private Int16 vrijePlaatsenValue;
public Int32 VoorstellingsNr
{
get { return voorstellingsNrValue; }
set { voorstellingsNrValue = value; }
}
public String Titel
{
get { return titelValue; }
set { titelValue= value; }
}
public String Uitvoeders
{
get { return uitvoedersValue; }
set { uitvoedersValue = value; }
}
public DateTime Datum
{
get { return datumValue; }
set { datumValue = value; }
}
public Int32 GenreNr
{
get { return genreNrValue; }
set { genreNrValue = value; }
}
public Decimal Prijs
{
get { return prijsValue; }
set { prijsValue = value; }
}
public Int16 VrijePlaatsen
{
get { return vrijePlaatsenValue; }
set { vrijePlaatsenValue = value; }
}
public Voorstellingen(Int32 nVoorstellingsNr, String nTitel, String nUitvoerders, DateTime nDatum, Int32 nGenreNr, Decimal nPrijs, Int16 nVrijePlaatsen)
{
this.VoorstellingsNr = nVoorstellingsNr;
this.Titel = nTitel;
this.Uitvoeders = nUitvoerders;
this.Datum = nDatum;
this.GenreNr = nGenreNr;
this.Prijs = nPrijs;
this.VrijePlaatsen = nVrijePlaatsen;
}
public Voorstellingen(Int32 nVoorstellingsNr, String nTitel, String nUitvoerders, DateTime nDatum, Decimal nPrijs, Int16 nVrijePlaatsen)
{
this.VoorstellingsNr = nVoorstellingsNr;
this.Titel = nTitel;
this.Uitvoeders = nUitvoerders;
this.Datum = nDatum;
this.Prijs = nPrijs;
this.VrijePlaatsen = nVrijePlaatsen;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Gemeenschappelijk
{
public class Voorstellingen
{
private Int32 voorstellingsNrValue;
private String titelValue;
private String uitvoedersValue;
private DateTime datumValue;
private Int32 genreNrValue;
private Decimal prijsValue;
private Int16 vrijePlaatsenValue;
public Int32 VoorstellingsNr
{
get { return voorstellingsNrValue; }
set { voorstellingsNrValue = value; }
}
public String Titel
{
get { return titelValue; }
set { titelValue= value; }
}
public String Uitvoeders
{
get { return uitvoedersValue; }
set { uitvoedersValue = value; }
}
public DateTime Datum
{
get { return datumValue; }
set { datumValue = value; }
}
public Int32 GenreNr
{
get { return genreNrValue; }
set { genreNrValue = value; }
}
public Decimal Prijs
{
get { return prijsValue; }
set { prijsValue = value; }
}
public Int16 VrijePlaatsen
{
get { return vrijePlaatsenValue; }
set { vrijePlaatsenValue = value; }
}
public Voorstellingen(Int32 nVoorstellingsNr, String nTitel, String nUitvoerders, DateTime nDatum, Int32 nGenreNr, Decimal nPrijs, Int16 nVrijePlaatsen)
{
this.VoorstellingsNr = nVoorstellingsNr;
this.Titel = nTitel;
this.Uitvoeders = nUitvoerders;
this.Datum = nDatum;
this.GenreNr = nGenreNr;
this.Prijs = nPrijs;
this.VrijePlaatsen = nVrijePlaatsen;
}
public Voorstellingen(Int32 nVoorstellingsNr, String nTitel, String nUitvoerders, DateTime nDatum, Decimal nPrijs, Int16 nVrijePlaatsen)
{
this.VoorstellingsNr = nVoorstellingsNr;
this.Titel = nTitel;
this.Uitvoeders = nUitvoerders;
this.Datum = nDatum;
this.Prijs = nPrijs;
this.VrijePlaatsen = nVrijePlaatsen;
}
}
}
public Voorstellingen VoorstellingOpzoeken(int voorstellingsNr)
{
var manager = new CultuurCentrumDbManager();
{
using (var conCultuur = manager.GetConnection())
{
using (var comVoorstelling = conCultuur.CreateCommand())
{
comVoorstelling.CommandType = CommandType.StoredProcedure;
comVoorstelling.CommandText = "VoorstellingSpec";
var parVoorstellingsNr = comVoorstelling.CreateParameter();
parVoorstellingsNr.ParameterName = "@voorstellingsNr";
parVoorstellingsNr.Value = voorstellingsNr;
comVoorstelling.Parameters.Add(parVoorstellingsNr);
var parTitel = comVoorstelling.CreateParameter();
parTitel.ParameterName = "@titel";
parTitel.DbType = DbType.String;
parTitel.Size = 50;
parTitel.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parTitel);
var parUitvoerders = comVoorstelling.CreateParameter();
parUitvoerders.ParameterName = "@uitvoerders";
parUitvoerders.DbType = DbType.String;
parUitvoerders.Size = 50;
parUitvoerders.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parUitvoerders);
var parDatum = comVoorstelling.CreateParameter();
parDatum.ParameterName = "@datum";
parUitvoerders.DbType = DbType.DateTime;
parDatum.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parDatum);
var parPrijs = comVoorstelling.CreateParameter();
parPrijs.ParameterName = "@prijs";
parPrijs.DbType = DbType.Currency;
parPrijs.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parPrijs);
var parVrijePlaatsen = comVoorstelling.CreateParameter();
parVrijePlaatsen.ParameterName = "@vrijePlaatsen";
parVrijePlaatsen.DbType = DbType.Int16;
parVrijePlaatsen.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parVrijePlaatsen);
conCultuur.Open();
comVoorstelling.ExecuteNonQuery();
if (parTitel.Value.Equals(DBNull.Value))
{
throw new Exception("Voorstelling niet gevonden");
}
return new Voorstellingen(
(int)parVoorstellingsNr.Value,
parTitel.Value.ToString(),
parUitvoerders.Value.ToString(),
(DateTime)parDatum.Value,
(Decimal)parPrijs.Value,
(Int16)parVrijePlaatsen.Value);
}
}
}
{
var manager = new CultuurCentrumDbManager();
{
using (var conCultuur = manager.GetConnection())
{
using (var comVoorstelling = conCultuur.CreateCommand())
{
comVoorstelling.CommandType = CommandType.StoredProcedure;
comVoorstelling.CommandText = "VoorstellingSpec";
var parVoorstellingsNr = comVoorstelling.CreateParameter();
parVoorstellingsNr.ParameterName = "@voorstellingsNr";
parVoorstellingsNr.Value = voorstellingsNr;
comVoorstelling.Parameters.Add(parVoorstellingsNr);
var parTitel = comVoorstelling.CreateParameter();
parTitel.ParameterName = "@titel";
parTitel.DbType = DbType.String;
parTitel.Size = 50;
parTitel.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parTitel);
var parUitvoerders = comVoorstelling.CreateParameter();
parUitvoerders.ParameterName = "@uitvoerders";
parUitvoerders.DbType = DbType.String;
parUitvoerders.Size = 50;
parUitvoerders.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parUitvoerders);
var parDatum = comVoorstelling.CreateParameter();
parDatum.ParameterName = "@datum";
parUitvoerders.DbType = DbType.DateTime;
parDatum.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parDatum);
var parPrijs = comVoorstelling.CreateParameter();
parPrijs.ParameterName = "@prijs";
parPrijs.DbType = DbType.Currency;
parPrijs.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parPrijs);
var parVrijePlaatsen = comVoorstelling.CreateParameter();
parVrijePlaatsen.ParameterName = "@vrijePlaatsen";
parVrijePlaatsen.DbType = DbType.Int16;
parVrijePlaatsen.Direction = ParameterDirection.Output;
comVoorstelling.Parameters.Add(parVrijePlaatsen);
conCultuur.Open();
comVoorstelling.ExecuteNonQuery();
if (parTitel.Value.Equals(DBNull.Value))
{
throw new Exception("Voorstelling niet gevonden");
}
return new Voorstellingen(
(int)parVoorstellingsNr.Value,
parTitel.Value.ToString(),
parUitvoerders.Value.ToString(),
(DateTime)parDatum.Value,
(Decimal)parPrijs.Value,
(Int16)parVrijePlaatsen.Value);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Common;
using System.Data;
using Gemeenschappelijk;
namespace WebApplication1
{
public partial class Reserveren : System.Web.UI.Page
{
int voorstellingsNr;
protected void Page_Load(object sender, EventArgs e)
{
try
{
var manager = new CultuurcentrumMethods();
voorstellingsNr = int.Parse(Server.UrlDecode(Request.QueryString["nr"]));
var voorstelling = manager.VoorstellingOpzoeken(voorstellingsNr);
LabelDatum.Text = voorstelling.Datum.ToString();
LabelPrijs.Text = voorstelling.Prijs.ToString();
LabelUitvoerders.Text = voorstelling.Uitvoeders;
LabelVoorstelling.Text = voorstelling.Titel;
LabelVrijePlaatsen.Text = voorstelling.VrijePlaatsen.ToString();
}
catch (Exception ex)
{
LabelVoorstelling.Text = ex.Message;
LabelDatum.Text = string.Empty;
LabelPrijs.Text = string.Empty;
LabelUitvoerders.Text = string.Empty;
LabelVoorstelling.Text = string.Empty;
LabelVrijePlaatsen.Text = string.Empty;
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Common;
using System.Data;
using Gemeenschappelijk;
namespace WebApplication1
{
public partial class Reserveren : System.Web.UI.Page
{
int voorstellingsNr;
protected void Page_Load(object sender, EventArgs e)
{
try
{
var manager = new CultuurcentrumMethods();
voorstellingsNr = int.Parse(Server.UrlDecode(Request.QueryString["nr"]));
var voorstelling = manager.VoorstellingOpzoeken(voorstellingsNr);
LabelDatum.Text = voorstelling.Datum.ToString();
LabelPrijs.Text = voorstelling.Prijs.ToString();
LabelUitvoerders.Text = voorstelling.Uitvoeders;
LabelVoorstelling.Text = voorstelling.Titel;
LabelVrijePlaatsen.Text = voorstelling.VrijePlaatsen.ToString();
}
catch (Exception ex)
{
LabelVoorstelling.Text = ex.Message;
LabelDatum.Text = string.Empty;
LabelPrijs.Text = string.Empty;
LabelUitvoerders.Text = string.Empty;
LabelVoorstelling.Text = string.Empty;
LabelVrijePlaatsen.Text = string.Empty;
}
}
}
}
Wie kan mij een beetje helpen hiermee? Thnx alvast
