|
-
Sep 28th, 2004, 01:03 AM
#1
Thread Starter
Lively Member
Object reference not set to an instance of an object
Hi:
i get this message quite often. below is part of the code which gives the error. can u find anything wrong?
Dim ac, desc As String
ac = e.Item.Cells(0).Text
desc = e.Item.Cells(1).Text
Dim sqlselect As String
Dim conn1 As New OleDb.OleDbConnection("Provider=MSDAORA.1;Password=eas;User ID=eas;Data Source=WETST920.world")
sqlselect = "select * from subarea where upper (code) ='" & UCase(ac) & "' "
Dim del As New OleDb.OleDbCommand(sqlselect, conn1)
conn1.Open()
del.ExecuteNonQuery()
conn1.Close()
dscmd.SelectCommand.CommandText = sqlselect
dscmd.Fill(ds, sqlselect)
the error comes at
dscmd.SelectCommand.CommandText = sqlselect
why??
thanks
-
Sep 28th, 2004, 01:19 AM
#2
Where is dscmd declared at? You must create an instance of it before using it.
Dim dscmd As New Dataset()
-
Sep 28th, 2004, 01:23 AM
#3
Thread Starter
Lively Member
I defined them as:
Public dscmd As New OleDb.OleDbDataAdapter()
Public ds As New DataSet()
-
Sep 28th, 2004, 01:34 AM
#4
Originally posted by Sheikha
I defined them as:
Public dscmd As New OleDb.OleDbDataAdapter()
Public ds As New DataSet()
try to do like this:
VB Code:
Public dscmd As OleDb.OleDbDataAdapter
dscmd = New OleDb.OleDbDataAdapter("select * from subarea where upper (code) ='" & UCase(ac) & "' ",conn1)
-
Sep 28th, 2004, 01:37 AM
#5
You are referencing the SelectCommand of the DataAdapter before it is set to anything. Try:
VB Code:
'instead of this
dscmd.SelectCommand.CommandText = sqlselect
'use this
dscmd.SelectCommand=del
Also there is no need to Execute this command before the fill since it doesn't do anything and gets executed again during the fill. So you can remove this:
VB Code:
conn1.Open()
del.ExecuteNonQuery()
conn1.Close()
-
Sep 28th, 2004, 01:37 AM
#6
Thread Starter
Lively Member
thanks... it works...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|