Hi

i am new in .Net2.0,Before this i had familier with .net1.0.
i had written the code for insertion of values in database throgh form & i m getting it successful,Now i want to display the database values in the respective textboxes as i selected one value from the listbox on the selectedindex_changed event.
for this i had written the following code.

Private Sub LoadSelectedRecord()
Dim con As OracleConnection
Dim cmd As OracleCommand
Dim dr As OracleDataReader
Dim strSelect As String

Try

strSelect = "SELECT * FROM tblTimingMaster WHERE sTimingName = '" & Replace(lstsearch.Text, "'", "''") & "'"
con = New OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings("DeepakConnectionString").ConnectionString)
con.Open()

cmd = New OracleCommand(strSelect, con)
dr = cmd.ExecuteReader()

' Loop through the result set using the datareader class.
' The datareader is used here because all that is needed
' is a forward only cursor which is more efficient.
Do While dr.Read()
txtenglish.Text = dr.Item("sTimingName")
If Not IsDBNull(dr.Item("sTimingNameInMarathi")) Then
txtmarathi.Text = dr.Item("sTimingNameInMarathi")
Else
txtmarathi.Text = ""
End If

If Not IsDBNull(dr.Item("sTimingNameInGujrathi")) Then
txtgujrati.Text = dr.Item("sTimingNameInGujarati")
Else
txtgujrati.Text = ""
End If

If Not IsDBNull(dr.Item("sTimingNameInKannada")) Then
txtkannada.Text = dr.Item("sTimingNameInKannada")
Else
txtkannada.Text = ""
End If


Loop

dr.Close()
cmd.Dispose()
con.Close()
'con.Dispose()

Catch e As OracleException
MsgBox(e.Message, MsgBoxStyle.Information, "Deepak Fertilizer")

Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Information, "Deepak Fertilizer")
End Try
End Sub
then called this method on selectedindex_changed event of listbox.
but don't able to get the desired outpt. & getting the message that unable to find the specified column in result set.....why this is so??????
reply me as soon as possible.

thanx!!!

Hi, I would change the way you are doing this. This might just be a personal preference, but I would rather load the result into a GridView then add the GridView items to the list.

Dim conn1 as Data.SqlClient.SqlConnection(STRING)
Dim SELECT1 as String
SELECT1 = "Your Select String"
Dim GridViewX as new GridView
Dim DataTableX as new data.datable
Dim Adapter1 as new Data.SqlClient.SqlDataAdapter(SELECT1, conn1)
conn1.open
Adapter1.Fill(DataTableX)
conn1.close
GridViewX.DataSource = DataTableX
GridViewX.Databind

Dim NumRows as Integer
NumRows = GridViewX.Rows.Count - 1
Dim NewItem as ?New? ListItem

Do While NumRows >=0

NewItem.Text = GridViewX.Rows(NumRows).Cells(COLUMN-NUMBER).text
NewItem.Value = GridViewX.Rows(NumRows).Cells(COLUMN-NUMBER).text
ListBox1.Items.Add(NewItem)

NumRows = NumRows - 1

Loop

That should populate the list with the items.

Also, remember, your cell column starts with 0, not 1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.