我正在嘗試使用C#
在WindowsForms
應用程序中創建我的第一個員工管理器。我差不多完成了,但是顯示了一個我無法糾正的錯誤。不是所有的路徑返回值 - Windows Form App - C#
它是:
「CS0161 - 並非所有的代碼路徑返回一個值」
我試過,我覺得這裏的一切,但沒有結果......我要求你幫幫我!
namespace WPC
{
public static class WPCDB
{
public static SqlConnection GetConnection()
{
string connStr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=c: \users\volko\onedrive\документи\visual studio 2015\Projects\WPC\WPC\WPC.mdf;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
return conn;
}
public static void AddEmployee(string IDnumber, string firstName, string fatherName, string lastName, string departament, float salary, DateTime date)
{
string insStmt = "INSERT INTO TABLE EMPLOYEE (Idnumber, firstName, fatherName, lastName, department, salary, date) VALUES (@IDnumber, @firstName, @fatherName, @lastName, @department @salary, @date)";
SqlConnection conn = GetConnection();
SqlCommand insCmd = new SqlCommand(insStmt, conn);
insCmd.Parameters.AddWithValue("@IDnumber", IDnumber);
insCmd.Parameters.AddWithValue("@firstName", firstName);
insCmd.Parameters.AddWithValue("@fatherName", fatherName);
insCmd.Parameters.AddWithValue("@lastName", lastName);
insCmd.Parameters.AddWithValue("@department", departament);
insCmd.Parameters.AddWithValue("@department", salary);
insCmd.Parameters.AddWithValue("@department", date);
try
{
conn.Open(); insCmd.ExecuteNonQuery();
}
catch (SqlException ex) { throw ex; }
finally { conn.Close(); }
}
public static List<Employee> GetEmployee()
{
List<Employee> employeelist = new List<Employee>();
SqlConnection conn = GetConnection();
string selStmt = "SELECT * FROM EMPLOYEE ORDER BY IDnumber, FirstName"; //employee table = table
SqlCommand selcmd = new SqlCommand(selStmt, conn);
try
{
conn.Open();
SqlDataReader reader = selcmd.ExecuteReader();
while (reader.Read())
{
Employee employee = new Employee();
employee.EmployeeNumber = (int)reader["EmployeeNumber"];
employee.IDnumber = reader["IDnumber"].ToString();
employee.FirstName = reader["FirstName"].ToString();
employee.FatherName = reader["FatherName"].ToString();
employee.LastName = reader["LastName"].ToString();
employee.Depart = reader["Depart"].ToString();
employee.Salary = (float)reader["Salary"];
employee.Date = (DateTime)reader["Date"];
employeelist.Add(employee);
}
reader.Close();
}
catch (SqlException ex) { throw ex; }
finally { conn.Close(); }
}
}
}
預先感謝您的時間!