Showing posts with label somebody. Show all posts
Showing posts with label somebody. Show all posts

Thursday, March 22, 2012

Object reference not set to an instance of an object.

Can somebody pllease tell me what is the error on this code. I got the error
on the executereader line.

Public Function verificarcedula(ByVal cedula As String) As Boolean

Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
cod_empl=@dotnet.itags.org.cedula", SqlConnection1)

mycmd.Parameters.Add("@dotnet.itags.org.cedula", cedula)

Dim myreader As SqlDataReader

Try

SqlConnection1.Open()

myreader = mycmd.ExecuteReader

If (myreader.Read) Then

Return True

Else

Return False

End If

Catch ex As Exception

Throw ex

Finally

myreader.Close()

SqlConnection1.Close()

End Try

End Function

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEVWhich line ?

You have an object that is not created (ie. Nothing).

--

"Luis Esteban Valencia" <luisvalen@.haceb.com> a crit dans le message de
news:eECvzGZxEHA.1988@.TK2MSFTNGP12.phx.gbl...
> Can somebody pllease tell me what is the error on this code. I got the
error
> on the executereader line.
> Public Function verificarcedula(ByVal cedula As String) As Boolean
> Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
> cod_empl=@.cedula", SqlConnection1)
> mycmd.Parameters.Add("@.cedula", cedula)
> Dim myreader As SqlDataReader
> Try
> SqlConnection1.Open()
> myreader = mycmd.ExecuteReader
> If (myreader.Read) Then
> Return True
> Else
> Return False
> End If
> Catch ex As Exception
> Throw ex
> Finally
> myreader.Close()
> SqlConnection1.Close()
> End Try
> End Function
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 2.
> MIEMBRO ACTIVO DE ALIANZADEV
This line.

myreader = mycmd.ExecuteReader

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
"Patrice" <nobody@.nowhere.com> escribi en el mensaje
news:uS2ArOZxEHA.3096@.TK2MSFTNGP14.phx.gbl...
> Which line ?
> You have an object that is not created (ie. Nothing).
> --
> "Luis Esteban Valencia" <luisvalen@.haceb.com> a crit dans le message de
> news:eECvzGZxEHA.1988@.TK2MSFTNGP12.phx.gbl...
> > Can somebody pllease tell me what is the error on this code. I got the
> error
> > on the executereader line.
> > Public Function verificarcedula(ByVal cedula As String) As Boolean
> > Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
> > cod_empl=@.cedula", SqlConnection1)
> > mycmd.Parameters.Add("@.cedula", cedula)
> > Dim myreader As SqlDataReader
> > Try
> > SqlConnection1.Open()
> > myreader = mycmd.ExecuteReader
> > If (myreader.Read) Then
> > Return True
> > Else
> > Return False
> > End If
> > Catch ex As Exception
> > Throw ex
> > Finally
> > myreader.Close()
> > SqlConnection1.Close()
> > End Try
> > End Function
> > --
> > LUIS ESTEBAN VALENCIA
> > MICROSOFT DCE 2.
> > MIEMBRO ACTIVO DE ALIANZADEV
Try creating the dataReader object with the new keyword
Dim myreader As New SqlDataReader
+++++++++++++++++++++++++++++++

"Luis Esteban Valencia" wrote:

> Can somebody pllease tell me what is the error on this code. I got the error
> on the executereader line.
> Public Function verificarcedula(ByVal cedula As String) As Boolean
> Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
> cod_empl=@.cedula", SqlConnection1)
> mycmd.Parameters.Add("@.cedula", cedula)
> Dim myreader As SqlDataReader
> Try
> SqlConnection1.Open()
> myreader = mycmd.ExecuteReader
> If (myreader.Read) Then
> Return True
> Else
> Return False
> End If
> Catch ex As Exception
> Throw ex
> Finally
> myreader.Close()
> SqlConnection1.Close()
> End Try
> End Function
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 2.
> MIEMBRO ACTIVO DE ALIANZADEV
>
Well, the reader object reference is only being assigned to in this
line of code, so it should not be a problem (and the ExecuteReader
method will take care of creating the object in any case). If anything
it is the SqlCommand object that we need to be suspicious of, but it
looks as if it was New'ed appropriately.

Have you stepped through the code with the debugger Luis?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 8 Nov 2004 09:39:02 -0800, "Tampa .NET Koder"
<TampaNETKoder@.discussions.microsoft.com> wrote:

>Try creating the dataReader object with the new keyword
>Dim myreader As New SqlDataReader
>+++++++++++++++++++++++++++++++
>
>"Luis Esteban Valencia" wrote:
>> Can somebody pllease tell me what is the error on this code. I got the error
>> on the executereader line.
>>
>> Public Function verificarcedula(ByVal cedula As String) As Boolean
>>
>> Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
>> cod_empl=@.cedula", SqlConnection1)
>>
>> mycmd.Parameters.Add("@.cedula", cedula)
>>
>> Dim myreader As SqlDataReader
>>
>> Try
>>
>> SqlConnection1.Open()
>>
>> myreader = mycmd.ExecuteReader
>>
>> If (myreader.Read) Then
>>
>> Return True
>>
>> Else
>>
>> Return False
>>
>> End If
>>
>> Catch ex As Exception
>>
>> Throw ex
>>
>> Finally
>>
>> myreader.Close()
>>
>> SqlConnection1.Close()
>>
>> End Try
>>
>> End Function
>>
>>
>> --
>> LUIS ESTEBAN VALENCIA
>> MICROSOFT DCE 2.
>> MIEMBRO ACTIVO DE ALIANZADEV
>>
>>
>
Did you checked they are not Nothing ? I would check also SqlConnection1.

Patrice

--

"Luis Esteban Valencia" <luisvalen@.haceb.com> a crit dans le message de
news:e1qoHUZxEHA.2600@.TK2MSFTNGP09.phx.gbl...
> This line.
> myreader = mycmd.ExecuteReader
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 2.
> MIEMBRO ACTIVO DE ALIANZADEV
> "Patrice" <nobody@.nowhere.com> escribi en el mensaje
> news:uS2ArOZxEHA.3096@.TK2MSFTNGP14.phx.gbl...
> > Which line ?
> > You have an object that is not created (ie. Nothing).
> > --
> > "Luis Esteban Valencia" <luisvalen@.haceb.com> a crit dans le message de
> > news:eECvzGZxEHA.1988@.TK2MSFTNGP12.phx.gbl...
> > > Can somebody pllease tell me what is the error on this code. I got the
> > error
> > > on the executereader line.
> > > > Public Function verificarcedula(ByVal cedula As String) As Boolean
> > > > Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
> > > cod_empl=@.cedula", SqlConnection1)
> > > > mycmd.Parameters.Add("@.cedula", cedula)
> > > > Dim myreader As SqlDataReader
> > > > Try
> > > > SqlConnection1.Open()
> > > > myreader = mycmd.ExecuteReader
> > > > If (myreader.Read) Then
> > > > Return True
> > > > Else
> > > > Return False
> > > > End If
> > > > Catch ex As Exception
> > > > Throw ex
> > > > Finally
> > > > myreader.Close()
> > > > SqlConnection1.Close()
> > > > End Try
> > > > End Function
> > > > > --
> > > LUIS ESTEBAN VALENCIA
> > > MICROSOFT DCE 2.
> > > MIEMBRO ACTIVO DE ALIANZADEV
> >

Friday, March 16, 2012

Object reference not set to an instance of an object.

Can somebody pllease tell me what is the error on this code. I got the error
on the executereader line.
Public Function verificarcedula(ByVal cedula As String) As Boolean
Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
cod_empl=@dotnet.itags.org.cedula", SqlConnection1)
mycmd.Parameters.Add("@dotnet.itags.org.cedula", cedula)
Dim myreader As SqlDataReader
Try
SqlConnection1.Open()
myreader = mycmd.ExecuteReader
If (myreader.Read) Then
Return True
Else
Return False
End If
Catch ex As Exception
Throw ex
Finally
myreader.Close()
SqlConnection1.Close()
End Try
End Function
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEVWhich line ?
You have an object that is not created (ie. Nothing).
"Luis Esteban Valencia" <luisvalen@.haceb.com> a crit dans le message de
news:eECvzGZxEHA.1988@.TK2MSFTNGP12.phx.gbl...
> Can somebody pllease tell me what is the error on this code. I got the
error
> on the executereader line.
> Public Function verificarcedula(ByVal cedula As String) As Boolean
> Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
> cod_empl=@.cedula", SqlConnection1)
> mycmd.Parameters.Add("@.cedula", cedula)
> Dim myreader As SqlDataReader
> Try
> SqlConnection1.Open()
> myreader = mycmd.ExecuteReader
> If (myreader.Read) Then
> Return True
> Else
> Return False
> End If
> Catch ex As Exception
> Throw ex
> Finally
> myreader.Close()
> SqlConnection1.Close()
> End Try
> End Function
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 2.
> MIEMBRO ACTIVO DE ALIANZADEV
>
This line.
myreader = mycmd.ExecuteReader
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
"Patrice" <nobody@.nowhere.com> escribi en el mensaje
news:uS2ArOZxEHA.3096@.TK2MSFTNGP14.phx.gbl...
> Which line ?
> You have an object that is not created (ie. Nothing).
> --
> "Luis Esteban Valencia" <luisvalen@.haceb.com> a crit dans le message de
> news:eECvzGZxEHA.1988@.TK2MSFTNGP12.phx.gbl...
> error
>
Try creating the dataReader object with the new keyword
Dim myreader As New SqlDataReader
+++++++++++++++++++++++++++++++
"Luis Esteban Valencia" wrote:

> Can somebody pllease tell me what is the error on this code. I got the err
or
> on the executereader line.
> Public Function verificarcedula(ByVal cedula As String) As Boolean
> Dim mycmd As SqlCommand = New SqlCommand("select * from maestro where
> cod_empl=@.cedula", SqlConnection1)
> mycmd.Parameters.Add("@.cedula", cedula)
> Dim myreader As SqlDataReader
> Try
> SqlConnection1.Open()
> myreader = mycmd.ExecuteReader
> If (myreader.Read) Then
> Return True
> Else
> Return False
> End If
> Catch ex As Exception
> Throw ex
> Finally
> myreader.Close()
> SqlConnection1.Close()
> End Try
> End Function
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 2.
> MIEMBRO ACTIVO DE ALIANZADEV
>
>
Well, the reader object reference is only being assigned to in this
line of code, so it should not be a problem (and the ExecuteReader
method will take care of creating the object in any case). If anything
it is the SqlCommand object that we need to be suspicious of, but it
looks as if it was New'ed appropriately.
Have you stepped through the code with the debugger Luis?
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 8 Nov 2004 09:39:02 -0800, "Tampa .NET Koder"
<TampaNETKoder@.discussions.microsoft.com> wrote:
>Try creating the dataReader object with the new keyword
>Dim myreader As New SqlDataReader
>+++++++++++++++++++++++++++++++
>
>"Luis Esteban Valencia" wrote:
>
Did you checked they are not Nothing ? I would check also SqlConnection1.
Patrice
"Luis Esteban Valencia" <luisvalen@.haceb.com> a crit dans le message de
news:e1qoHUZxEHA.2600@.TK2MSFTNGP09.phx.gbl...
> This line.
> myreader = mycmd.ExecuteReader
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 2.
> MIEMBRO ACTIVO DE ALIANZADEV
> "Patrice" <nobody@.nowhere.com> escribi en el mensaje
> news:uS2ArOZxEHA.3096@.TK2MSFTNGP14.phx.gbl...
>

Object reference not set to an instance of an object. - Help!

Hi! Somebody plz help me with this problem? I don't know what's happen.

In may web.config i have my connection, then i get this error when compile de code.

</system.web>

<appSettings>

<addkey="Conexao"value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\Economato\Economato.mdb;"/>

</appSettings>

</configuration>

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 37: .DataTextField = "Estado"Line 38: .DataValueField = "Estado"Line 39: .DataSource = GetDados(SqlString).Tables("dados").DefaultViewLine 40: .DataBind()Line 41: End With

Source File:C:\Inetpub\wwwroot\Economato\Utilizador\Requisita.aspx.vb Line:39
First off, may I suggest not putting absolute paths in your connection string. Change it to...

<addkey="Conexao"value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Economato.mdb;"/>
Also, we need to see the code on the page that has.DataSource = GetDados(SqlString).Tables("dados").DefaultView
Looks like you may have a blank field in your database (maybe) that you didn't account for when reading.
Or, your SqlString was not set, or your table "dados" is mispelled.
Could be any number of things,
Zath


My SqlString is this:

PrivateSub Page_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load

'Put user code to initialize the page here

IfNot Page.IsPostBackThen

Dim SqlStringAsString = "SELECT Distinct Estado FROM ItemRequisicao"

With dropestado

.DataTextField = "Estado"

.DataValueField = "Estado"

.DataSource = GetDados(SqlString).Tables("dados").DefaultView

.DataBind()

EndWith

dropestado_SelectedIndexChanged(sender, e)

EndIf

EndSub


The code on the page that has the data source is this:
(I've 2 function to getdados and get the value that i need)

PublicFunction GetDados(ByVal SqlStringAsString)As DataSet

Try

Dim ConnAsNew OleDbConnection(Conexao)

Dim daAsNew OleDbDataAdapter(SqlString, Conn)

Dim dsAsNew DataSet

Conn.Open()

da.Fill(ds, "dados")

Conn.Close()

Return ds

Catch eAs OleDbException

'Throw e

EndTry

EndFunction

PublicFunction GetValorPedido(ByVal SqlStringAsString)AsString

Try

Dim ConnAsNew OleDbConnection(Conexao)

Dim CmdAsNew OleDbCommand(SqlString, Conn)

Conn.Open()

Dim ValorAsString = Cmd.ExecuteScalar()

Conn.Close()

Return Valor

Catch eAs OleDbException

Throw e

EndTry

EndFunction


I've this code for my SqlString:

PrivateSub Page_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load

'Put user code to initialize the page here

IfNot Page.IsPostBackThen

Dim SqlStringAsString = "SELECT Distinct Estado FROM ItemRequisicao"

With dropestado

.DataTextField = "Estado"

.DataValueField = "Estado"

.DataSource = GetDados(SqlString).Tables("dados").DefaultView

.DataBind()

EndWith

dropestado_SelectedIndexChanged(sender, e)

EndIf

EndSub
Then i've this 2 functions:

PublicFunction GetDados(ByVal SqlStringAsString)As DataSet

Try

Dim ConnAsNew OleDbConnection(Conexao)

Dim daAsNew OleDbDataAdapter(SqlString, Conn)

Dim dsAsNew DataSet

Conn.Open()

da.Fill(ds, "dados")

Conn.Close()

Return ds

Catch eAs OleDbException

'Throw e

EndTry

EndFunction

PublicFunction GetValorPedido(ByVal SqlStringAsString)AsString

Try

Dim ConnAsNew OleDbConnection(Conexao)

Dim CmdAsNew OleDbCommand(SqlString, Conn)

Conn.Open()

Dim ValorAsString = Cmd.ExecuteScalar()

Conn.Close()

Return Valor

Catch eAs OleDbException

Throw e

EndTry

EndFunction


Change your code to the following and try again:

With dropestado

.DataSource = GetDados(SqlString).Tables("dados").DefaultView
.DataTextField = "Estado"

.DataValueField = "Estado"

.DataBind()

EndWith


Nothing!...I don't know what's happen, but the problem continues. I already verified the database, but all Ok meets there!

Try this:

.DataSource = GetDados(SqlString)


Ok! Now i've the same problem in other side of my code :s

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 75: Dim SqlString As StringLine 76: SqlString = "SELECT Requisicao.NumReq, Requisicao.DataRequisicao, Requisicao.Codigo_utilizador, ItemRequisicao.Estado FROM Requisicao INNER JOIN ItemRequisicao ON Requisicao.NumReq = ItemRequisicao.NumReq"Line 77: SqlString += "WHERE ItemRequisicao.Estado = '" & dropestado.SelectedItem.Value & "'"Line 78: With dgRequisicaoLine 79: .DataSource = GetDados(SqlString).Tables("dados").DefaultView

Source File:C:\Inetpub\wwwroot\Economato\Utilizador\Requisita.aspx.vb Line:77
The function is this:

PrivateSub dropestado_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles dropestado.SelectedIndexChanged

Dim SqlStringAsString

SqlString = "SELECT Requisicao.NumReq, Requisicao.DataRequisicao, Requisicao.Codigo_utilizador, ItemRequisicao.Estado FROM Requisicao INNER JOIN ItemRequisicao ON Requisicao.NumReq = ItemRequisicao.NumReq"

SqlString += "WHERE ItemRequisicao.Estado = ' " & dropestado.SelectedItem.Value & " ' "

With dgRequisicao

.DataSource = GetDados(SqlString).Tables("dados").DefaultView

.DataBind()

EndWith

With dgmateriais

.DataSource =Nothing

.DataBind()

EndWith

EndSub


Hi,
any chance that there would be no item selected in DropDownList in question (SelectedIndex is -1), when SelectedItem property would return null and trying to access its Value proeprty would then throw NullreferenceException.

Try to debug your code and comment out the green code and see if the DDL is populated or not.

IfNot Page.IsPostBackThen

Dim SqlStringAsString = "SELECT Distinct Estado FROM ItemRequisicao"

With dropestado

.DataSource = GetDados(SqlString)
.DataTextField = "Estado"

.DataValueField = "Estado"

.DataBind()

EndWith

'dropestado_SelectedIndexChanged(sender, e)

EndIf

EndSub


Ok! I do that and the is what u said, the DDL is not populated. But, what i don't understand is why not? Could somebody tell me?

You may try something like these first:

PublicFunction GetDados(ByVal SqlStringAsString)As DataSet

Try

Dim ConnAsNew OleDbConnection(Conexao)

Dim daAsNew OleDbDataAdapter(SqlString, Conn)

Dim dsAsNew DataSet

Conn.Open()

da.Fill(ds, "dados")

Conn.Close()
'See if there is any data back

Dim intRetrun as Integer = ds.Tables("dados").Rows.Count

Return ds

Catch eAs OleDbException

'See if you can catch any exception here
Throw e

EndTry

EndFunction


Hi! Sorry for the time, but i had some problems and just now i've time to work again in my project. I tried that and an exception come and i think that the real problem is with the connection, but i want know if i'm right.

Server Error in '/Economato' Application.

N?o foi possível encontrar o arquivo 'C:\WINDOWS\system32\Economato.mdb'.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Data.OleDb.OleDbException: N?o foi possível encontrar o arquivo 'C:\WINDOWS\system32\Economato.mdb'.
Source Error:

Line 57: Catch e As OleDbExceptionLine 58: 'See if you can catch any exception hereLine 59: Throw eLine 60: End TryLine 61: End Function


Could you translate the messages that you posted? That could help identify what's going on.

Thanks for the aid, but I think that already solved the problem for now.Was a problem that had with the connection with the Database.
Thank u!