Перехват сообщения хранимой процедуры/триггера из SQL server в C# windows forms
я создал простое приложение для входа в систему, где, если я ввел правильные данные, оно даст мне нужные данные, иначе, если я введу данные, которые не имеют записи, моя хранимая процедура выполнит RAISERROR.
вот моя папка code DAL
public List<globalVariables> getRecords(string employeeName) { globalVariables variables = new globalVariables(); var credentials = new List<globalVariables>(); var test = new List<globalVariables>(); using (SqlConnection oConnection = new SqlConnection(variables.sqlConnection)) { using (SqlCommand oCommand = new SqlCommand("spGetallinfor", oConnection)) { oCommand.Connection = oConnection; oCommand.CommandType = CommandType.StoredProcedure; oCommand.Parameters.AddWithValue("@employeeFirstname", employeeName); SqlDataReader oReader = null; try { oConnection.Open(); oReader = oCommand.ExecuteReader(); while (oReader.Read()) { variables.employeeFirstname = oReader["employeeFirstname"].ToString(); variables.employeePhoto = (byte[])oReader["employeeImage"]; credentials.Add(variables); } } catch (SqlException ex) { throw; } } } return credentials; }
в моем балу
public List<globalVariables> getEmployeerecord(string employeeName) { try { return imageConnection.getRecords(employeeName); } catch (Exception ex) { throw; } }
и в моей winform
if (e.KeyCode == Keys.Enter) { string name = txtName.Text; List<globalVariables> result = imageBL.getEmployeerecord(name); try { foreach (var item in result) { lblName.Text = item.employeeFirstname; byte[] byteResult = new byte[0]; byteResult = item.employeePhoto; MemoryStream imageResult = new MemoryStream(byteResult); pictureBox1.Image = Image.FromStream(imageResult); } } catch (Exception ex) { throw; } }
Моя хранимая процедура
CREATE PROC [dbo].[spGetallinfor] @employeeFirstname varchar(50) AS BEGIN IF EXISTS (SELECT * FROM tutorials WHERE employeeFirstname = @employeeFirstname) BEGIN SELECT employeeFirstname, employeeImage FROM tutorials WHERE employeeFirstname = @employeeFirstname END ELSE RAISERROR('Employee (%s) does not exists', 16, 0, @employeeFirstname) END
Что я уже пробовал:
я попытался поместить глобальную переменную в catch, но когда я попытался поместить ее в метку в winform, она исчезла.