SQLite 插入在 DAL 中不起作用,没有出现错误?
SQLite insert does not work in DAL, no errors appear?
我是 SQlite 数据库的新手。
我正在尝试在 sqlite db table "time_sheet_info" 中插入一条新记录,
我从 .asmx WebService 调用 DAL 方法;没有错误; ExecuteNonQuery returns 1;但没有数据出现。
我试图在 WebService 中执行插入命令;它在那里完美运行!!
有什么建议吗?
**注意:我使用自动生成的代理访问 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);
}
}
达尔:
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();
}
}
您必须在 using
块的末尾调用 scope.Complete
即:
using (TransactionScope scope = new TransactionScope())
{
obj1.SaveData(arrData);
scope.Complete();
}
我是 SQlite 数据库的新手。
我正在尝试在 sqlite db table "time_sheet_info" 中插入一条新记录,
我从 .asmx WebService 调用 DAL 方法;没有错误; ExecuteNonQuery returns 1;但没有数据出现。
我试图在 WebService 中执行插入命令;它在那里完美运行!!
有什么建议吗?
**注意:我使用自动生成的代理访问 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);
}
}
达尔:
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();
}
}
您必须在 using
块的末尾调用 scope.Complete
即:
using (TransactionScope scope = new TransactionScope())
{
obj1.SaveData(arrData);
scope.Complete();
}