Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, February 18, 2010 8:58 PM
Ive created a program that uses a SQL select statement to retrieve certain data from an access database, such as SELECT DATE WHERE Score=10;. This works if the item is specified as 0 but will only retrieve the first result, and im using navigation buttons so i want to be able to view all of them one at a time. So i tried changing item to the column the data is located in (which is 1) and the row will vary depending on what button is pressed. but i now get an error message saying "cannot find column 1"
TextBox2.Text = ds.Tables(
"table1").Rows(count - 1).Item(1)
Any help please????
All replies (6)
Thursday, February 18, 2010 9:08 PM ✅Answered | 1 vote
if you are only Selecting from the DATE column, as in your example, the resulting datatable will only have 1 Column, which would be Index = 0
that is why when you change it to 0 it works, but when you change it to 1 it can't find that Column
did you try
SELECT * FROM Table_Name WHERE Score = 10
this will return all the columns from your table, and only those rows where Score = 10. Then if the Date is the second column (which would be Index = 1) it should work
Tuesday, February 23, 2010 10:01 AM ✅Answered
Hi 3101MM,
I'm not sure i get your question. Do you mean you want to show data in datatable one by one using TextBox and BindingNavigator?
Here is an example.
Imports System.Data.SqlClient
Public Class Form1
Const constr As String = "server=(local);database=TestDB;uid=sa;pwd=sa;"
Private bd As BindingSource = New BindingSource
Private dt As DataTable = New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim adapter As SqlDataAdapter = New SqlDataAdapter("select * from customers", constr)
adapter.Fill(dt)
bd.DataSource = dt
BindingNavigator1.BindingSource = bd
TextBox1.DataBindings.Add("Text", bd, "FirstName")
End Sub
End Class
If i misunderstand you, please let me know.
Regards
Jeff ShanPlease remember to mark the replies as answers if they help and unmark them if they provide no help.
Friday, February 19, 2010 10:55 AM
Thanks, I understand what your saying, i have just tried that but now i get a new error message " there is no row at position 1".
Maybe im just doing this wrong. Im actually trying to select the data from column 1 (i think as its the second column in my table) starting from the first row (which currently works) but then retrieving each row after that one at a time...
Im i doing it wrong?
Friday, February 19, 2010 11:15 AM
Strange as it the first time was working.
So you should have changed more then only the date in an asterix
What is your table name by the way, you did not give that to us?
Success
Cor
Friday, February 19, 2010 11:18 AM | 1 vote
you probably got the error " there is no row at position 1" coz your query returned only one row which basically resides at 0 index in the data table.
Mark the post answered or helpful if you feel so. http://www.ishan-solution.blogspot.com
Friday, February 19, 2010 11:35 AM
The table name is just table1. Cyber if this is the case how do i return the row 1 then after return row 0, which is it currently doing already?? i want to be able to replace the first row returned with the second row returned and so on....