我正在开发一个非常简单的Web服务,并希望得到一些帮助。我从Visual Studio中获取了库存Web服务,并开始使用非常有限的ODP.NET知识对其进行修改。
实际上,我正在尝试做的是从SQL查询中返回一组结果,其中包含一个我传递给服务的变量。在我的查询正常工作后,WR_Premise是我想要合并的变量。我使用WCF测试客户端调用我的函数,但是当我尝试运行以下代码时,我得到InvalidOperationException
。
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Dim wrpremise As Integer
Dim state As String
Dim queryString As String = _
"select MV_OUTAGE_DURATION.CAUSE_DESC, MV_OUTAGE_DURATION.DEV_NAME, MV_OUTAGE_DURATION.DEV_TYPE_NAME, MV_OUTAGE_DURATION.EVENTNUM, MV_OUTAGE_DURATION.OUT_MINUTES, MV_OUTAGE_DURATION.OFF_DTS , MV_OUTAGE_DURATION.RESTORE_DTS , MV_OUTAGE_DURATION.SYS_RESP_TYPE from MV_we_outage_premise, MV_OUTAGE_DURATION where mv_we_outage_premise.evntnum = MV_OUTAGE_DURATION.eventnum and mv_we_outage_premise.we_premise = '995184' order by(MV_OUTAGE_DURATION.RESTORE_DTS)"
Dim command As New OracleCommand(queryString)
value = wrpremise
Dim oradb As String = "Data Source=****;User Id=******;Password=***********;"
Dim conn As New OracleConnection(oradb)
conn.Open()
state = conn.State.ToString()
command.ExecuteNonQuery()
MsgBox(state)
conn.Close()
state = conn.State.ToString()
MsgBox(state)
Return String.Format("You entered: {0}", value)
End Function
当我将command.ExecuteNonQuery()
退出服务时,我可以让服务工作并返回状态,但这对我没什么帮助...
另外,任何人都知道将结果输出到XML的简单方法吗?
答案 0 :(得分:1)
查询中的两个问题
对于命令连接,请使用
command.Connection = conn
用于检索记录
Dim reader as OracleDataReader = command.ExecuteReader()
while (reader.Read())
{
... use your data
}
在此处参阅OracleDataReader的参考资料,此处参考OraclaDataAdapter