2

嗨,我想了解如何将 java 代码转换为 C#,我阅读了一些关于 java 的教程,但我没有找到如何翻译这行代码的方法:

CallableStatement cstmt = con.prepareCall("?=CALL
cstmt.registerOutParameter(1, Types.JAVA_OBJECT);
cstmt.execute(); 
ResultSet rs = (ResultSet) cstmt.getObject(1); 

我尝试

  CUBRIDConnection con = new CUBRIDConnection(ConnectionString);
  CUBRIDCommand com = new CUBRIDCommand();
  com.CommandType = CommandType.StoredProcedure;
  com.Connection = con;
  com.CommandText = "call mySP();";
  com.Parameters.Add("?=p", CUBRIDDataType.CCI_U_TYPE_RESULTSET).Direction =
      ParameterDirection.Output;
  con.Open();
  DbDataReader df = com.ExecuteReader(CommandBehavior.SingleResult);
  //some stuff
  con.Close();

这不起作用,我该如何翻译?

4

3 回答 3

2

尝试这个

 SqlConnection con = new SqlConnection("your connection string");
    SqlCommand com = new SqlCommand();
    com.CommandType = CommandType.StoredProcedure;
    com.Connection = con;
    com.CommandText = "yourstoredprocedurename"; //no paranthesis or call key word just procedure name
    SqlParameter parameter = new SqlParameter("yourparametername", SqlDbType.Binary); //just parameter name no questionmark
    parameter.Direction= ParameterDirection.Output;
    com.Parameters.Add(parameter);
    con.Open();
    var df = com.ExecuteReader(CommandBehavior.SingleResult);
    //some stuff
    con.Close();
于 2012-05-11T21:03:27.117 回答
1

我概述了以下可以改进以帮助它工作的行:

SqlConnection con = new SqlConnection("ValidConnectionString");    

com.CommandText = "storedProcedureName"; // You need to give the command the actual SP name, call mySP(); is invalid.

com.Parameters.Add("@ParameterName", SqlDbType.Binary).Direction = ParameterDirection.Output; // Parameters are usually prefixed with @ParameterName (some people omit the @) however this is preference amongst developers.

注意:您必须用您的 connectionString 替换“ValidConnectionString”(除非 ConnectionString 是保存此信息的变量)。如果不是,则连接字符串如下所示: Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; 它将连接到 SQL Server 2008 数据库。对于其他连接字符串,请查看以下站点:

http://www.connectionstrings.com/

于 2012-05-11T21:04:55.773 回答
0

我使用以下方法解决它。

http://www.cubrid.org/?mid=forum&category=195532&document_srl=358924

于 2012-05-14T17:26:00.660 回答