SQLite插入在DAL中不起作用,不会出现错误?

时间:2016-08-08 08:43:40

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

我是SQlite数据库的新手。
我试图在sqlite db table" time_sheet_info"中插入一条新记录, 我从.asmx WebService调用DAL方法; &安培;没有错误; ExecuteNonQuery返回1;但没有数据出现。
我试图在WebService中执行insert命令;它在那里工作得很好!!

有什么建议吗?

**注意:我使用自动生成的PROXY访问WS。

GUI:

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();
        }
    }

1 个答案:

答案 0 :(得分:1)

您必须在scope.Complete块结束时致电using,即:

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