pej*_*man 0 c# asp.net webmethod
我有一个方法(带WebMethod属性),我定义了一个事务,在我的方法和我的事务中我调用了2个存储过程,第一个是GetAllBook:
select *
from Book_TBL
where IsActive = 'True'
Run Code Online (Sandbox Code Playgroud)
第二个是updateBook:
update Book_TBL
set IsActive = 'False'
where IsActive = 'True'
Run Code Online (Sandbox Code Playgroud)
和我的方法:
public struct BOOK
{
public string BOOK_NAME;
public string BOOK_DESC;
}
[WebMethod]
public static List<BOOK> GetMyBooks()
{
using (TransactionScope _transactionScope = new TransactionScope(TransactionScopeOption.Required))
{
string _connString = "Data Source=.;Initial Catalog=BookStore;Integrated Security=True";
SqlConnection _conn = new SqlConnection(_connString);
_conn.Open();
SqlCommand _com = new SqlCommand();
_com.CommandType = System.Data.CommandType.StoredProcedure;
_com.CommandText = "GetAllBook";
_com.Connection = _conn;
SqlDataAdapter bookdataAdapter = new SqlDataAdapter(_com);
DataSet bookDS = new DataSet();
bookdataAdapter.Fill(bookDS, "Book_TBL");
List<BOOK> bookList = new List<BOOK>();
_conn.Close();
BOOK book;
foreach (DataRow dr in bookDS.Tables["Book_TBL"].Rows)
{
book = new BOOK();
book.BOOK_NAME = dr["book_name"].ToString();
book.BOOK_DESC = dr["book_desc"].ToString();
bookList.Add(book);
}
SqlCommand updateCommand= new SqlCommand();
_conn.Open();
updateCommand.CommandText = "updateBook";
updateCommand.CommandType = System.Data.CommandType.StoredProcedure;
updateCommand.Connection = _conn;
updateCommand.ExecuteNonQuery();
_conn.Close();
return bookList;
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行项目时,myMethod给我一些书籍列表,IsActive = True但它没有更新我的表格!问题是什么?
| 归档时间: |
|
| 查看次数: |
76 次 |
| 最近记录: |