Sub BindData()
...
dim cmd as OleDbCommand
...
dim objDr as OleDbDataReader
objDr = cmd.ExecuteReader()' error: Object reference not set to an instance of an object.
DropDownList8.SELECTEDITEM.text = objDr.item( "LYLT" )...
How can I read and print record on screen from db.Hi,
I don't see you instantiating the OleDbCommand anywhere?
You posted code:
dim cmd as OleDbCommand
This is just declaring the variable but are you instantiating the OleDbCOmmand somewhere?
i.e
dim cmd asNew OleDbCommand
Also you need to call Read method for DataReader at least once before accessing any of its items. And inside If loop i.e
If objDr.Read() Then
DropDownList8.SELECTEDITEM.text = objDr.item( "LYLT" )
End If
objDr.Close
Still continue this error,
I instanting OleDbCommand like;
dim dbbag as new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; DATA Source=d:\..\...mdb")
dbbag.open()dim cmd as OleDbCommand
Cmd = new OleDbCommand("Select * from bck1 order by date desc", dbbag)DropDownList8.SELECTEDITEM.text = objDr.item( "LOYALTY" )
Did you read the last couple of lines in my previous post? You need to call the Read method of OleDbDataReader at least once before you can access its contents (of course, create the reader using ExecuteReader before trying to loop through it)
Sorry,
I can understand why call the read method inside if or for loop and how can call!
I think I can't explain my problem because of in pieces codes.
My whole code;
Sub BindData()dim dbbag as new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; DATA Source=d:\...\...mdb")
dbbag.open()
dim cmd as OleDbCommand
Cmd = new OleDbCommand("Select * from bcksrv1 order by TARIH desc", dbbag)dim objDr as OleDbDataReader
objDr = cmd.ExecuteReader()if objDr.Read()then
respons.text = objDr.item("RESPONS")
DropDownList8.SELECTEDITEM.text = objDr.item( "LOYALTY" )
end if
objDr.Close()
Many Than for your patience
Ok,
and you get the error in the:
DropDownList8.SELECTEDITEM.text = objDr.item( "LOYALTY" )
Try to change that as follows:
DropDownList8.SelectedIndex=DropDownList8.Items.IndexOf(DropDownList8.Items.FindByText(objDr.item( "LOYALTY" )))
e.g if the field LOYALTY matches the text in DropDownList, it selects it. If you want to do the same but based on DropDownList values, you'd use FindByValue method of Items property (ListItemCollection). Note that this assumes that the field is non-null.
But another question is that what does your query return? You are trying to select from DDL what the first row of the query returns?
I.It ir running BUT list is empty.
Sub Page_Load(Obj as Object, E as eventargs)
If Not Page.IsPostBack Then
BindData
end if
end subSub BindData()
dim dbbag as new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; DATA Source=d:\...\...mdb")
dbbag.open()dim Cmd as new OleDbCommand("Select * from bcksrv1 order by TARIH desc", dbbag)
dim objDr as OleDbDataReader
objDr = Cmd.ExecuteReader()if objDr.Read()then
DropDownList8.SELECTEDITEM.text = objDr.item( "LOYALTY" )
end if
II. It is running :?
Sub Page_Load(Obj as Object, E as eventargs)If Not IsPostBack Then
dim dbbag as new OledbConnection("provider=Microsoft.Jet.OLEDB.4.0; DATA Source=d:\...\...mdb")
dbbag.open()dim cmd as New OledbCommand("Select * from bcksrv1 order by TARIH desc", dbbag)
dim objDr as OleDbDataReader
objDr= cmd.ExecuteReader()If veri.read() then
DropDownList8.SELECTEDITEM.text = objDr.item( "LOYALTY" )
What is your opionion.? and suggestion about first example.
2. question How can call the sub Page_load somewhere?
0 comments:
Post a Comment