From: Martin <mc...@we...> - 2004-01-16 02:43:09
|
Hi, I have now tried the C# code below using the cast that was provided. I still get an exception of "Specified cast is not valid." the C# code that I have used is shown below. The stored procedure that I am using is shown below also. There is definatly a record comming back. at least if I use a fbdatareader and loop then the loop only ueses a single record. I am not sure how to get the value back from a data reader. It seems strange that the cast works for you and not me I am using RC2. Thanks again for any advice. cheers martin. try { Context.Trace.Warn("Page_Load","Entered function"); FirebirdSql.Data.Firebird.FbConnection objConn = new FirebirdSql.Data.Firebird.FbConnection(); FirebirdSql.Data.Firebird.FbCommand objCMD = new FirebirdSql.Data.Firebird.FbCommand(); objConn.ConnectionString = "Database=C:\\Inetpub\\wwwroot\\nz\\_database\\RESTOREDB.GDB;User=SYSDBA;Pas sword=masterkey;Dialect=3;Server=localhost;Pooling=false;"; objConn.Open(); objCMD.Connection = objConn; Context.Trace.Write("Page_Load","connection is open"); objCMD.CommandText = "SP_EE_GET_GROUP_DESCRIPTION"; objCMD.CommandType = CommandType.StoredProcedure; FirebirdSql.Data.Firebird.FbParameter P1 = new FirebirdSql.Data.Firebird.FbParameter(); P1.Direction = ParameterDirection.Input; P1 = objCMD.Parameters.Add("@ID", 87); FirebirdSql.Data.Firebird.FbDataReader dr; dr = objCMD.ExecuteReader(); string value = (string)objCMD.ExecuteScalar(); objConn.Close(); Context.Trace.Warn("Page_Load","Exited function"); } catch (Exception ex) { Context.Trace.Warn("Excepetion thrown"); Context.Trace.Write(ex.Message); } store procedure text CREATE PROCEDURE SP_EE_GET_GROUP_DESCRIPTION ( ID INTEGER) RETURNS ( DISPLAY_DESCRIPTION BLOB SUB_TYPE 0 SEGMENT SIZE 80) AS BEGIN FOR SELECT EE_SP_NAME.DISPLAY_DESCRIPTION FROM EE_SP_SCHEDULE INNER JOIN EE_SP_NAME ON (EE_SP_SCHEDULE.EE_SP_NAME_ID = EE_SP_NAME.ID) WHERE ( (EE_SP_SCHEDULE.ID = :ID) ) INTO :DISPLAY_DESCRIPTION DO BEGIN SUSPEND; END END ""Martin"" <mc...@we...> wrote in message news:bu79g2$38v$1...@ne...... > Hi, > > I am using .net provider 1.5 RC2. > I am using vb.net code. The line that is throwing the exception is > > strDesciption = CType(objCMD.ExecuteScalar(), String) > > and the exception description is > > Cast from type 'Byte()' to type 'String' is not valid. > > I have checked that a record is being broght back. Perhaps I have the cast > syntax wrong... > > The full code that I am using is below. If I comment the cat out and just > use > > objCMD.ExecuteScalar() > > then all works fine. > > I am executing a stored procedure. and the full code that I am using is > below for reference. > > > cheers > > martin. > > > > Try > Dim objConn As FirebirdSql.Data.Firebird.FbConnection = New > FirebirdSql.Data.Firebird.FbConnection > Dim objCMD As FirebirdSql.Data.Firebird.FbCommand = New > FirebirdSql.Data.Firebird.FbCommand > Dim objTran As FirebirdSql.Data.Firebird.FbTransaction > objConn.ConnectionString = > System.Configuration.ConfigurationSettings.AppSettings("DbConnectionString") > objConn.Open() > objCMD.Connection = objConn > objTran = objConn.BeginTransaction() > objCMD.Transaction = objTran > objCMD.CommandText = "SP_EE_GET_GROUP_DESCRIPTION" > objCMD.CommandType = CommandType.StoredProcedure > Dim P1 As New FirebirdSql.Data.Firebird.FbParameter > P1.Direction = ParameterDirection.Input > P1 = objCMD.Parameters.Add("@ID", 87) > Dim strDesciption As String 'Variable to hold the description > string that will be returned > > strDesciption = CType(objCMD.ExecuteScalar(), String) > <<<<<<<<<<<<<<<<<<<<--------- THROWS EXCEPTION > > > objCMD.Dispose() > objTran.Commit() > objTran.Dispose() > objConn.Close() > Catch ex As Exception > Trace.Write(ex.Message()) > End Try > > > > > > > "Carlos Guzmán Álvarez" <car...@te...> wrote in message > news:400...@te...... > > Hello: > > > > > BLOB SUB_TYPE 1 SEGMENT SIZE 80 CHARACTER SET NONE > > > > It's correct, which version of the .NET Data Provider are you using ?? > > > > I have tested this with 1.5, and runs fine: > > > > FbConnection connection = new FbConnection(connectionString); > > connection.Open(); > > > > string sql = "select clob_field from test where int_field = 1"; > > > > FbCommand command = new FbCommand(sql, connection); > > > > string value = (string)command.ExecuteScalar(); > > > > connection.Close(); > > > > > > > > > > -- > > Best regards > > > > Carlos Guzmán Álvarez > > Vigo-Spain > > > > > > > > ------------------------------------------------------- > > The SF.Net email is sponsored by EclipseCon 2004 > > Premiere Conference on Open Tools Development and Integration > > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > > http://www.eclipsecon.org/osdn > > _______________________________________________ > > Firebird-net-provider mailing list > > Fir...@li... > > https://lists.sourceforge.net/lists/listinfo/firebird-net-provider > > > > > > > ------------------------------------------------------- > The SF.Net email is sponsored by EclipseCon 2004 > Premiere Conference on Open Tools Development and Integration > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > http://www.eclipsecon.org/osdn > _______________________________________________ > Firebird-net-provider mailing list > Fir...@li... > https://lists.sourceforge.net/lists/listinfo/firebird-net-provider > |