开发者

retrieving information from an oracle database

i am trying to use a dataset to obtain information from an oracle database i have build my application but i am receiving this error, how can i solve it ?

can开发者_运维技巧not convert from 'System.Data.OracleClient.OracleCommand' to 'System.Data.SqlClient.SqlCommand


There is extensive details about using the Oracle provider here:

http://download.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25312/building_odp.htm#CEGBBCEF

A snippet from these docs:

    string sql = "select department_name from departments where department_id = " +
      ":department_id";

OracleCommand cmd = new OracleCommand(sql, conn);
    cmd.CommandType = CommandType.Text;
    OracleParameter p_department_id = new OracleParameter(); 
    p_department_id.OracleDbType = OracleDbType.Decimal;     
    p_department_id.Value = 20;                              
    cmd.Parameters.Add(p_department_id);                     

    OracleDataReader dr = cmd.ExecuteReader();
    dr.Read();

    departments.Items.Add(dr.GetString(0));


The problem is you're trying to cast a OracleDBCommand, that is, a command that's specific for Oracle to a SQLCommand, that is, a command that's specific for SQLServer.

What you have to do, if you want to abstract, is to cast to the DBCommand class instead. DBCommand is the base class for all Command classes for specific provider command classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜