我在asp.net中创建了一个简单的休息服务mvc.my问题是我的值没有传递给respository
类。我想我想念一些人可以帮助..?
这是我的controller
static LoginRespository repository = new LoginRespository();
public string AddEmployees(Login Emp)
{
//calling EmpRepository Class Method and storing Repsonse
var response = repository.AddEmployees(Emp);
return response;
}
和我的respository
类就像这样
public string AddEmployees(Login Emp)
{
SqlCommand com;
SqlConnection con = new SqlConnection(@"Data Source=DOTNET;Initial Catalog=edin;Integrated Security=True;Pooling=False");
try
{
com = new SqlCommand("select * from data where name='" + Emp.username + "'", con);
con.Open();
SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
return "success";
}
else
{
return "error";
}
con.Close();
}
catch (Exception aa)
{
return aa.ToString();
}
}
我的model
是
public string username { get; set; }
public string password { get; set; }
答案 0 :(得分:0)
注意:
答案 1 :(得分:0)
如果您在按钮单击事件上调用AddEmployees。试试这个:
Emp employeeRec = new Emp();
employeeRec.username = txtName.text;
employeeRec.password = txtPassword.text;
AddEmployees(employeeRec);