我正在尝试将表单中的数据插入到数据库中的两个表中。
public ActionResult Cr([Bind(Include = "id,name,time")] appointment appointment, [Bind(Include = "pid,phone")] customer customer , string submit)
{
string str1 = "Insert Into appointment.id, appointment.name, appointment.time Values id,name,time"
string str2= "Insert Into customer.pid, customer.phone Values pid,phone"
var Query = dbb.Database.SqlQuery<ViewModel.custapp>(str1).ToList();
var Query = dbb.Database.SqlQuery<ViewModel.custapp>(str2).ToList();
return View("Index");
}
我不确定我的代码是否有误,但数据没有插入到表中。
最佳答案
你需要表名(列名)和值()
string str1 = "Insert Into appointment (id, name, time) Values (id,name,time)";
string str2= "Insert Into customer (pid, phone) Values (pid,phone)";
关于c# - ASP MVC 中的原始 SQL 'Insert Into',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43086402/