c# - SQLite插入在DAL中不起作用,没有出现错误?

标签 c# web-services sqlite data-access-layer

我是SQlite数据库的新手。
我正在尝试在sqlite数据库表“ time_sheet_info”中插入新记录,
我从.asmx WebService调用DAL方法;并没有错误; ExecuteNonQuery返回1;但没有数据出现。
我试图在WebService中执行insert命令;它在那里工作完美!!

有什么建议?
**注意:我使用自动生成的PROXY访问WS。

界面:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SaveDataDolCls data = new SaveDataDolCls();
            data.intProjectID = 1;
            data.intTaskID = 1;

            WebService1 wsp = new WebService1();
            wsp.saveData(data);
        }
    }


WS:

 [WebMethod]
    public void saveData(SaveDataDolCls arrData)
    {
        using (TransactionScope scope = new TransactionScope())
        {
            obj1.SaveData(arrData);
        }

    }


DAL:

SaveDataDolCls obj = new SaveDataDolCls();
    public void SaveData(SaveDataDolCls arrData)
    {
        using (SQLiteConnection conn = new SQLiteConnection())
        {
            string dbPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DB\\MySqliteDb.db");
            string connStr = "data source= " + dbPath + "; version=3;";
            conn.ConnectionString = connStr;
            conn.Open();
            using (SQLiteCommand cmd = new SQLiteCommand(conn))
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into time_sheet_info (project_id, task_id) values ('1','3');";
                int i = cmd.ExecuteNonQuery();
            }
            conn.Close();
        }
    }

最佳答案

您必须在scope.Complete块的末尾调用using,即:

using (TransactionScope scope = new TransactionScope())
{
    obj1.SaveData(arrData);
    scope.Complete();
}

关于c# - SQLite插入在DAL中不起作用,没有出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38824741/

相关文章:

c# - 使用 .Net Interop 从 Excel 获取 DateTime 值时缺少毫秒数

asp.net - 什么会在一台服务器上导致此错误,而不是另一台服务器?

android - 如何解析web服务返回给android的.net数据集

c# - SyncRoot 模式有什么用?

c# - 直接从另一个 Web API Controller 内部调用另一个 Web API Controller

c# - 无法使用数据注释在 MVC 4 中设置日期时间格式

php - 如何使用 php 主机/服务器在两个 android 设备之间部署连接

django - 从 Django 应用程序访问 sqlite3 shell 时出错

ios - SQLite - 获取不是以字母开头的记录 - IOS - Objective C

python - Pycharm环境不同于命令行