如何运行执行阅读器 [英] how to run execute reader
本文介绍了如何运行执行阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
i have following code
OdbcCommand Command = MainClass.Conn.CreateCommand();
Command.Connection = MainClass.Conn;
using (OdbcTransaction transaction = MainClass.Conn.BeginTransaction())
{
Command.Transaction = transaction;
try
{
string saveStOpen = "Insert Statement.. "; \\ This This Is SQL Statement
Command.CommandText = saveStOpen;
Command.ExecuteNonQuery();
string saveGRNSub = "Insert Statement.."; \\ This This Is SQL
Command.CommandText = saveGRNSub;
Command.ExecuteNonQuery();
OdbcCommand OpenTemp = new OdbcCommand("SELECT * FROM GRN_TEMP WHERE (UserName = '" + MainClass.GetComputerName() + "')", MainClass.Conn);
OdbcDataAdapter da = new OdbcDataAdapter(OpenTemp);
DataTable dt = new DataTable();
da.Fill(dt); \\ This Point Genarate An Error
if (dt.Rows.Count >0)
{
MessageBox.Show(dt.Rows.Count.ToString());
}
//}
//readTemp.Dispose();
transaction.Commit();
at da.Fill(dt);
生成错误(executereader要求该命令进行事务处理)
如何避免此错误
我非常感谢
Generate Error (executereader requires the command to have a transaction )
how to avoid this error
I highly appreciate in advance
推荐答案
您需要在命令中设置连接对象后设置事务
检查此示例
http://msdn.microsoft.com/en-us/library/2k2hy99x%28v = vs.71%29.aspx [ ^ ]
You need to set the transaction after setting the connection object in command
Check this example
http://msdn.microsoft.com/en-us/library/2k2hy99x%28v=vs.71%29.aspx[^]
在填充数据表之前打开连接
Open the Connection Before Filling the DataTable
这篇关于如何运行执行阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文