我正在尝试从C#
运行存储过程,我一直收到错误:
名称为t1000的游标不存在
这是我的SQL语法,但它看起来像光标t1000确实存在?
Select emcd
INTO #UpdateThese
from dailylistedinformation
WHERE CAST(RescheduledDate As Date) = CAST(GETDATE() As Date)
Declare @t1000 int
DECLARE t1000 CURSOR FOR
SELECT emcd
FROM #UpdateThese
OPEN t1000
FETCH NEXT FROM t1000 INTO @t1000
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE FROM production
WHERE emcd = @t1000
INSERT INTO production (name, address, phone, email, zip, city, state)
SELECT name, address, phone, email, zip, city, state
from dailylistedinformation
where CAST(RescheduledDate As Date) = CAST(GETDATE() As Date)
FETCH NEXT FROM t1000 INTO @t1000
END
CLOSE t1000
DEALLOCATE t1000
这是我的C#我是如何调用它的,它每次都会遇到catch块并产生上述错误:
private void DoSomethingCrazy()
{
DoSomethingCrazy();
}
public DataSet DoSomethingCrazy()
{
_dataSet = new DataSet();
SqlQueryBuilder = new StringBuilder();
SqlQueryBuilder.Append("exec dbo.runstoredprocedure ");
_dataSet = ExecuteSqlQuery(databaseConnection, SqlQueryBuilder.ToString());
return _dataSet;
}
public DataSet ExecuteSqlQuery(string connectionString, string sqlQuery)
{
try
{
_connectionString = System.Configuration.ConfigurationManager.AppSettings[connectionString].ToString();
_sqlDatabaseConnection = new SqlConnection(_connectionString);
_sqlCommand = new SqlCommand(sqlQuery, _sqlDatabaseConnection);
_sqlDatabaseConnection.Open();
_sqlCommand.CommandTimeout = 0;
_dataSet = new DataSet();
_sqlDataAdapter = new SqlDataAdapter(_sqlCommand);
_sqlDataAdapter.Fill(_dataSet, "Data");
return _dataSet;
}
catch (Exception exception) { throw exception; }
finally
{
_sqlDatabaseConnection.Close();
_sqlCommand.Dispose();
_sqlDataAdapter.Dispose();
}
}