in your store procedure all your code below return @Durum is not executed.
You should use the return statement at the end of the stored procedure'.
Since the return statement kan only hold 1 integer you cannot use return.
You should end with select @Durum, @Sonuc
You don't need output parameters in your call to the database.
Your stored procedure should be:
ALTER proc [dbo].[BelgeKayit]
(
@OgrenciNo int,
@BelgeId int,
@BelgeBaslik nvarchar(30),
@BelgeAciklama nvarchar(250)
)
as
declare @OgrenciKayitKontrol int
declare @BelgeKayitKontrol int
declare @Durum int
declare @Sonuc int
set @Durum=0
set @Sonuc=0
Set @OgrenciKayitKontrol=(select count(0) from Ogrenci where Ogrenci.OgrenciNo=@OgrenciNo)
if(@OgrenciKayitKontrol=1)
begin
insert into OgrenciBelge(OgrenciNo,BelgeId,BelgeBaslik,BelgeAciklama)
values(@OgrenciNo,@BelgeId,@BelgeBaslik,@BelgeAciklama)
set @Durum=1
end
Set @BelgeKayitKontrol=(select count(0) from OgrenciBelge where OgrenciBelge.OgrenciNo=@OgrenciNo and OgrenciBelge.BelgeId=@BelgeId)
if(@BelgeKayitKontrol=1)
begin
insert into OgrenciBelge(OgrenciNo,BelgeId,BelgeBaslik,BelgeAciklama)
values(@OgrenciNo,@BelgeId,@BelgeBaslik,@BelgeAciklama)
set @Sonuc=1
end
select @Durum, @Sonuc
Your c# should possibly be (see my questions in the code):
int durum = 0;
int sonuc = 0;
SqlParameter[] paramdizi = new SqlParameter[4]
{
new SqlParameter("@OgrenciNo",SqlDbType.Int),
new SqlParameter("@BelgeId",SqlDbType.Int) ,
new SqlParameter("@BelgeBaslik",SqlDbType.NVarChar),
new SqlParameter("@BelgeAciklama",SqlDbType.NVarChar)
};
paramdizi[0].Value = TxtOgrenciNo.Text;
paramdizi[1].Value = DrpBelgeTuru.SelectedValue;
paramdizi[2].Value = TxtDosyaBaslik.Text;
paramdizi[3].Value = TxtAciklama.Text;
using (SqlDataReader dr = baglan.ExecuteReader("BelgeKayit", CommandType.StoredProcedure, paramdizi))
{
while (dr.Read())
{
durum = dr.GetInt32(0);
sonuc = dr.GetInt32(1);
}
}
GridViewBelgeler.DataSource = new BelgeGoster(TxtOgrenciNo.Text, DrpBelgeTuru.SelectedValue, TxtDosyaBaslik.Text, TxtAciklama.Text);
GridViewBelgeler.DataBind();
if (durum == 0)
{
LabelDurum.Text = " Böyle bir ögrenci numarasi bulunmamaktadir. ";
}
else if (sonuc == 0)
{
LabelDurum.Text = " 0 ";
}
else
{
LabelDurum.Text = " 1 ";
}
SqlParameter[] paramdizi = new SqlParameter[6]
{
new SqlParameter("@OgrenciNo",SqlDbType.Int),
new SqlParameter("@BelgeId",SqlDbType.Int) ,
new SqlParameter("@BelgeBaslik",SqlDbType.NVarChar),
new SqlParameter("@BelgeAciklama",SqlDbType.NVarChar) ,
new SqlParameter("@Durum",SqlDbType.Int),
new SqlParameter("@Sonuc",SqlDbType.Int)
};
paramdizi[0].Value = TxtOgrenciNo.Text;
paramdizi[1].Value = DrpBelgeTuru.SelectedValue;
paramdizi[2].Value = TxtDosyaBaslik.Text;
paramdizi[3].Value = TxtAciklama.Text;
paramdizi[4].Direction = ParameterDirection.Output;
paramdizi[5].Direction = ParameterDirection.Output;
SqlDataReader dr = baglan.ExecuteReader("BelgeKayit", CommandType.StoredProcedure, paramdizi);
List<BelgeGoster> belgeler = new List<BelgeGoster>();
while (dr.Read())
{
BelgeGoster belge = new BelgeGoster(dr.GetInt32(0), dr.GetInt32(1), dr.GetString(2), dr.GetString(3));
belgeler.Add(belge);
}
GridViewBelgeler.DataSource = belgeler;
GridViewBelgeler.DataBind();
if (paramdizi[4].Value.ToString() == "0")
{
LabelDurum.Text = " Böyle bir ögrenci numarasi bulunmamaktadir.
</b>// you dont have student ID in your ogrenci table// </b>) ";
}
else if (paramdizi[5].Value.ToString() == "0")
{
LabelDurum.Text = "u add this file (now) ";
}
else
{
LabelDurum.Text = " u added this file from now";
}