简体   繁体   中英

ODBC connet cache database, call an stored procedure with parameters,no data return

Using ODBC to connet cache database, call an stored procedure with parameters,no data return,but no problem in the DBeaver(or any other tools) with same procedure. I'm sure connection string is right,other code is right too,but OdbcDataReader return null. Here is my code:

string sql;
sql= "CALL web_DHCSTM_JXGL.PublicHealth_VPatHospitalNEW('0008787','','')";
OdbcCommand com = new OdbcCommand(sql, conn);
OdbcDataReader dr3 = com.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

I'm using .net framework 4.0 MVC. There is a similar procedure I call it with the same approach,and that one works,and both of them works on the DBeaver,so wired...

If your connection is successful and your procedure exists in the DB. you may use these lines to Execute the SP

OdbcCommand ODBCCommand = new OdbcCommand("{CALL web_DHCSTM_JXGL.PublicHealth_VPatHospitalNEW('0008787','',''}", 
ODBCConnection);
ODBCCommand.CommandType = CommandType.StoredProcedure;
ODBCCommand.Parameters.AddWithValue("@Anyparam", Arslan_aslam);// if SP wants any parameters.DataTable DataTable = new DataTable();
OdbcDataAdapter ODBCDatadapter = new OdbcDataAdapter(ODBCCommand);
ODBCDatadapter.Fill(DataTable); // Datatable will be populated in the response of SP
ODBCDatadapter.Dispose();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM