Home > Software engineering >  Vb to read access the value of the specified location
Vb to read access the value of the specified location

Time:10-05

I have a data table 0. MDB to read form called CHS read the column with the value of SHT I want to read the fifth line, if is equal to the value text1 will make a list of the corresponding line 5 read text2 inside,

CodePudding user response:

This mainly by writing SQL statements, need other skill rarely,

CodePudding user response:

Scanning one eye, I create a new project, to join two text controls, text1 text input is 1, the back of the SQL statement conditions text1. The text is 1, then add the adodb library reference, to write a piece of code that is not in conformity with your request, is the same reason,

Cnopen a simple process, 'open the database, the omitted, cn, rs, is not explained,
Set the rs=New ADODB. You
Rs. Open the "SELECT employees. Employee ID, employee. Surname, employees. Name, employees. Position From where employees. Employee ID=" & amp; Text1. Text, cn, 1, 1
'If the rs. State & lt;> AdStateClosed Then rs. Close
Rs. MoveFirst
Dim I, a
For I=0 To rs. 'Fields. The Count - 1-1 b can also, b has the assignment in the front. The cycle instead of behind the five words, both the same, but it is different modular,
A=b & amp; Rs. Fields (I)
'CellAlignment (I)=flexAlignCenterCenter
Next
Text2. Text=a

CodePudding user response:

People don't know your database, the table name and field, record, just give me some principles,
For example, I use Microsoft northwind database, table named employees, query field as the employee ID, according to the content of the input control text1 to query, SQL statements roughly "select * from employee where employees ID=1", or in control after went like this:
"Select * from employee where employees ID=" & amp; Text1. Text

I outside the two text1 controls, add a command button that in text1 input 2, press the button, just recorded output to text2.

Private Sub Command1_Click ()
Cnopen 'open the database connection methods, explain omitted,
Set the rs=New ADODB. You
Rs. Open the "SELECT employees. Employee ID, employee. Surname, employees. Name, employees. Position From where employees. Employee ID=" & amp; Text1. Text, cn, 1, 1

Dim I, a
For I=0 To rs. Fields. The Count - 1
A=b & amp; Rs. Fields (I)
Next
Text2. Text=a
Rs. Close
Set the rs=Nothing
Cn. Close
The Set cn=Nothing

End Sub

In TEXT1 enter 1, you can return a record; Input 5, can return to a record, and display in TEXT2,

CodePudding user response:

More troublesome is the determination of "line 5"

Access data table will not guarantee data row, even if you are sure there are fifth in the row in the table, unless you're at query time using the Order By clause, according to one or some column values to sort, for example, you have automatic increment field, and the field values for 5 record is not deleted,

CodePudding user response:

What "the fifth line," this is the database and not excel

CodePudding user response:

reference 4 floor of123 response:
is the trouble is that the determination of "line 5"

Access data table will not guarantee data row, even if you are sure there are fifth in the row in the table, unless you're at query time using the Order By clause, according to one or some column values to sort, for example, you have automatic increment field, and the field values for 5 record is not deleted,


I know you mean. The access is fields. But now I ignore fields and line. I just read the fifth line. Your way I know. But the fifth line is will change from time to time. You all know when access to add things will change. But I as long as the fifth row. Is not to say that you're looking for a certain value.. I this is not fixed. Don't consider other. I can write. Why can't read the press line read?

CodePudding user response:

Fifth in the cinema why not 1 row number 5?
Why not 'clock when the fifth entered the fifth out?

CodePudding user response:

All is line 5, also said not fixed?
But I guess probably wanted to express the meaning of the building Lord, is you should want to say: I now of the query is 10 records, button, will it behind line 5 (line 15) the contents of the display, don't know this meaning?

CodePudding user response:

 
Dim adoConnection As New ADODB. Connection
AdoConnection. The ConnectionString="omit database link words"
AdoConnection. Open

Dim the rs As New ADODB. You
Rs. Open the "select SHT, the from CHS", adoConnection, adOpenKeyset, adLockReadOnly
If the rs. RecordCount & gt; 5 Then=
Rs. Move 4

If the rs. Fields (SHT)=text1. Text Then
Text2. Text=rs. Fields (" the ")
End the If
End the If

Rs. Close
Set the rs=Nothing

AdoConnection. Close
The Set adoConnection=Nothing

CodePudding user response:

dug grave shame
  • Related