执行存储过程在vb.net [英] Executing stored procedure in vb.net

查看:103
本文介绍了执行存储过程在vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Oracle执行一个存储函数或SQL通过vb.net。

I need to execute a stored function in oracle or sql through vb.net.

我创建了一个命令对象。根据不同的数据库类型(Oracle或SQL)我是preparing的

I created a command object. Depending on the database type(oracle or SQL) i am preparing the

命令文本选择函数名来自双(,,,,,,,????????); (对于Oracle) 加的函数的参数值

Command text as Select functionName(?,?,?,?,?,?,?,?) from dual; (For Oracle) Adding the parameter values of the function

现在执行的ExecuteScalar这不是说工作参数无效。

Now performing the ExecuteScalar which is not working saying invalid parameter.

这适用于ODBC连接字符串。但是,ODBC不使用64位。

This works with ODBC connection string. But ODBC doesn't with 64bit.

我的要求:code应通过采取值在运行时执行用户定义的存储过程

My Requirement: Code should execute a user defined stored procedure by taking the values at runtime.

谢谢 Rupesh

推荐答案

您的命令文本应该只是存储过程的名称没有选择,并确保您设置的命令类型的存储过程。看看这个链接,例如:

Your command text should be just the Stored procedure name without a select, and make sure you set the command type to stored procedure. Check out this link for example:

http://support.microsoft.com/kb/321718

甲骨文:

Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "OracleSP"
Dim p1 As OracleParameter
Dim p2 As OracleParameter

p1 = cmd.Parameters.Add("Param1", OracleType.NVarChar)
p1.Value = "Value1"
p2 = cmd.Parameters.Add("Param2", OracleType.Double)
p2.Value = 10

cmd.ExecuteNonQuery()

SQL Server的:

SQL Server:

  cmd.Connection = conn
  cmd.CommandType = CommandType.StoredProcedure
  cmd.CommandText = "SqlSP"
  cmd.Parameters.Add("@Param1", SqlDbType.Int)
  cmd.ExecuteNonQuery()

我不知道有关甲骨文公司的,因为我还没有做到(我认为它应该工作),但与SQL Server,你可以使用:

I am not sure about Oracle as I haven't done it (I think it should work) but with Sql server you can use:

SqlCommandBuilder.DeriveParameters(cmd) 

填充,而不是设置他们像我一样的SqlParametersCollection的命令。 <一href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.deriveparameters.aspx"相对=nofollow> MSDN文档

to populate the SqlParametersCollection on the command, instead of setting them like I did. MSDN documentation

之后,你可以循环通他们,并设置你的价值观是必要的。

After that you can loop thru them and set your values as necessary.

这篇关于执行存储过程在vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆