c# - ASP MVC 中的原始 SQL 'Insert Into'

标签 c# mysql sql asp.net-mvc

我正在尝试将表单中的数据插入到数据库中的两个表中。

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/

相关文章:

php - 在 PHP 中存储文件结构

PHP/html 电子邮件表单不再提交到 mysql 数据库

php - 使用选择输入删除数据库中的对象后尝试获取非对象的属性

mysql - 选择 mysql 中两个表的每月数据计数

java - 数据库查询以获取范围内的记录

c# - VS2013 似乎没有正确附加 - 调试器已附加但未配置为调试此未处理的异常

C# 编译器警告 1685

c# - XslCompiledTransform 与 XslTransform 以及 OOM 的比较好吗?

mysql - 如何在 Perl 中从 MySQL 获取最后一个错误

sql - 为什么在查询数据库时 nolock 很重要