maria t

maria t

  • NA
  • 12
  • 1.2k

sql trigger & c#

Nov 28 2016 6:54 AM
hi everyone.please help me...
why the message of RAISERROR in sql trigger, does'nt display in c# at runtime when my c# codes are running?????
 plssssssssssssssssss
***************my sql trigger 
CREATE TRIGGER [dbo].[trg_CheckBalance_me]
ON [dbo].[st_havaleh_info]
FOR INSERT,update
AS
BEGIN
SET NOCOUNT ON;
if ((select count_kala from st_seating where Code_kala=(select code_material from inserted )) < ((select count_unit from inserted)-(select count_unit from deleted)))
begin
ROLLBACK TRAN;
RAISERROR ('stock of materials are low in store', 16, 1);
return
end
END;
go
 
 
 **********************************c# code
try
{
if ((checkdate == true) && con.Back_Query("select output_no from st_havaleh_info where output_no='" + txt_output.Text + "' and code_material='" + txt_code_k.Text + "'") != "0")
if (MessageBox.Show("?????? ?????", "??????", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign) == DialogResult.Yes)
{
string query5 = "update st_havaleh_info set count_unit='" + txt_count.Text + "',code_material='" + txt_code_k.Text + "',name_material=N'" + txt_name_k.Text + "',opposite_party='" + txt_name_opposite.Text + "'"
+ ",code_unit='" + unit_code_1 + "' ,description=N'" + txt_des.Text + "' where output_no='" + txt_output.Text + "' and code_material='" + txt_code_k.Text + "'";
con.ExecuteNonQuery(query5, 1);
}
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
Console.WriteLine(ex.InnerException.Message);
}
}
*************************************************call connectionclass.executeNonQuery
 
public string ExecuteNonQuery(string CommandText,int par)
{
try
{
connection.Close();
connection.ConnectionString = ConnectionString;
connection.Open();
command.CommandText = CommandText;
command.Connection = connection;
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
if(par==1)
MessageBox.Show("done");
return "1";
}
catch
{
if (par == 1)
MessageBox.Show("error in saving");
return "0";
}
}
*************************************************************** 

Answers (4)