我是SQlite数据库的新手。
我试图在sqlite db table" 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);
}
}
[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();
}
}
答案 0 :(得分:1)
您必须在scope.Complete
块结束时致电using
,即:
using (TransactionScope scope = new TransactionScope())
{
obj1.SaveData(arrData);
scope.Complete();
}