在linq中插入存储过程 [英] insert stored procedure in linq
本文介绍了在linq中插入存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ALTER PROCEDURE dbo.Psave
@id int,@name nchar(10)
AS
insert into Table1 values(@id,@name)
RETURN
private void button2_Click(object sender, System.EventArgs e)
{
string _cs = @"Data Source=nafiseh-pc;Database=testlinq;Integrated Security = true;";
using (DataClasses1DataContext dc = new DataClasses1DataContext(_cs))
{
dc.DeferredLoadingEnabled = false;
try
{
dc.Connection.Open();
dc.Transaction = dc.Connection.BeginTransaction();
dc.pSave(6,"k");
}//end try
finally
{
if (null != dc.Connection && dc.Connection.State != System.Data.ConnectionState.Closed)
{
dc.Connection.Close();
}
}//end finaly
}//end using
}
但不要将任何数据插入到Table1中.
帮助我
but dont any data insert to Table1.
help me
推荐答案
快速浏览一下,我注意到的唯一一件事就是您正确启动了事务,但是在哪里提交呢?如果未提交,事务将在会话结束时自动回滚,因此您将看不到任何数据.
With a quick look the only thing I noticed is that you start a transaction correctly, but where do you commit it? If it isn''t committed, the transaction is automatically rolled back when the session ends so you would see no data.
这篇关于在linq中插入存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文