If you don't care about the ID, just SELECT COUNT(CLI_COD) FROM CLIENTES (etc etc)

That way ExecuteScalar() will return 0 if there are no rows, or >0 if there were rows. You won't have to check for NULL's that way.

Robert


----- Original Message ----- From: "Fabio Gomes" <[EMAIL PROTECTED]>
To: <firebird-net-provider@lists.sourceforge.net>
Sent: Thursday, April 27, 2006 12:20 PM
Subject: Re: [Firebird-net-provider] Getting a single value from the database in C#


This compiled but gave me this error when i executed the select:

System.NullReferenceException: Object reference not set to an instance of an
object.
  at Sistema.frmLogin.btnOk_Click(Object sender, EventArgs e) in
D:\Documents and Settings\suporte\Meus documentos\Visual Studio
2005\Projects\SGC\Sistema de Gestão Comercial\frmLogin.cs:line 30

oh god.. why this have to be so complicated?

here is my code:

           FbCommand cmd = new FbCommand("SELECT CLI_COD FROM CLIENTES
WHERE CLI_NOME='" + txtUsuario.ToString() + "'", cn);
           try {
               int i = (int) cmd.ExecuteScalar();
           } catch (Exception ex) {
               MessageBox.Show(ex.ToString());
           }

On 4/27/06, Jiri Cincura <[EMAIL PROTECTED]> wrote:

On 27.4.2006 20:18 Fabio Gomes wrote:
>             int i = cmd.ExecuteScalar();

Simpliest way: int i = (int)cmd.ExecuteScalar();


--
Jiri Cincura
http://www.cincura.net/


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider





-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to