An error occurred in a program. Could you help me !! Urgent!

Source: Internet
Author: User
An error occurred in a program. Could you help me !! Urgent! Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061220090748211.html
I want to export data from the database data table to stringgrid. I want to make a more intuitive input interface, use the time field (SJD) as the row, and output the Data Project and data number field as two columns, however Program The error occurred because fieldbyname could not be found when writing to ado_sjz, but I wrote it in the same way as I did last time, and the result was okay! Please help me to see what went wrong. Could you tell me how to better and more conveniently control the data input interface? Because you need to input data to the same multiple data items in different time periods! You can view the data of each time period and input the data of each time period at a Glance. The following is a program:
Procedure tsjxmzlr. button1click (Sender: tobject );
VaR
I: integer;
J: integer;
Begin
With adoq_sjz do
Begin
Adoq_sjz.close;
Adoq_sjz. SQL .clear;
Adoq_sjz. SQL .text: = 'select Phid, sjmc from hymcb where lxmc =: lxmc ';
Adoq_sjz.parameters.parambyname ('lxmc '). Value: = trim (cb_lx.text );
Adoq_sjz.open;
For I: = 0 to ADOQ_sjz.RecordCount-1 do
Begin
Sg_sjz.cells [0, I]: = adoq_sjz.fieldbyname ('phid'). asstring;
Sg_sjz.cells [1, I]: = adoq_sjz.fieldbyname ('sjmc '). asstring;
Adoq_sjz.next;
End;
End;
With adoq_sjz do
Begin
Adoq_sjz.close;
Adoq_sjz. SQL .clear;
Adoq_sjz. SQL .text: = 'select SJD from sjb where BD =: BD ';
Adoq_sjz.parameters.parambyname ('sjd '). Value: = trim (cbb_bd.text );
Adoq_sjz.open;
For J: = 0 to ADOQ_sjz.RecordCount-1 do
Begin
Sg_sjz.cols [J]: = adoq_sjz.fieldbyname ('sjd '). astring; // the error message [Error] sjzlr is displayed. PAS (118): incompatible types: 'tstrings 'and 'string'
Adoq_sjz.next;
End;
End;

It's useless for you to use with do here. Try the following program.
Procedure tsjxmzlr. button1click (Sender: tobject );
VaR
I: integer;
J: integer;
Begin
Adoq_sjz.close;
Adoq_sjz. SQL .clear;
Adoq_sjz. SQL .text: = 'select Phid, sjmc from hymcb where lxmc =: lxmc ';
Adoq_sjz.parameters.parambyname ('lxmc '). Value: = trim (cb_lx.text );
Adoq_sjz.open;
For I: = 0 to ADOQ_sjz.RecordCount-1 do
Begin
Sg_sjz.cells [0, I]: = adoq_sjz.fieldbyname ('phid'). asstring;
Sg_sjz.cells [1, I]: = adoq_sjz.fieldbyname ('sjmc '). asstring;
Adoq_sjz.next;
End;
Adoq_sjz.close;
Adoq_sjz. SQL .clear;
Adoq_sjz. SQL .text: = 'select SJD from sjb where BD =: BD ';
Adoq_sjz.parameters.parambyname ('sjd '). Value: = trim (cbb_bd.text );
Adoq_sjz.open;
For J: = 0 to ADOQ_sjz.RecordCount-1 do
Begin
Sg_sjz.cols [J]: = adoq_sjz.fieldbyname ('sjd '). astring; // the error message [Error] sjzlr is displayed. PAS (118): incompatible types: 'tstrings 'and 'string'
Adoq_sjz.next;
End;
End;

No!

Or that error!

Sg_sjz.cols [J]: = adoq_sjz.fieldbyname ('sjd '). astring; // the following error occurs: [Error]

The error is found. asstring; you should try a second, haha, not careful.

It indicates that your type is incorrect.
Sg_sjz.cols [J]: = adoq_sjz.fieldbyname ('sjd '). astring;
Changed:
Sg_sjz.cols [J]: = adoq_sjz.fieldbyname ('sjd '). Value

No, I tried it all!

It is mainly written here when adoq_sjz is followed by fieldbyname, so there will be no value or asstring behind it! Why?

I don't bring up either, but I can write it down. Delphi doesn't have good technical support for ado, but value and asstring will pop up later.

Sg_sjz.cols [J]: = adoq_sjz.fieldbyname ('sjd '). astring

Property Cols [index: integer]: tstrings;

Two types are inconsistent

Yes. Here is the error: sg_sjz.cols [J] should be changed to: sg_sjz.cells [J, 0], which can run. However, the interface cannot input data. What should I do? I want users to input data on a relatively intuitive interface! Do you have any better solutions?
For example:
Project 1 20 30 20 30
Project 2 20 30 10 30
Project 3 20 50 10 20
Project 4 54 30 90 10
In the database, the Data Project is a field, the time is a field, and the data value is a field.
How can this problem be solved?

It should be. asstring; not. astring; take a good look at your program.

Now I have taken a table like this from the database, but cannot input data! What should I do! Which means the above program can only display empty tables? Thank you!

You are using tstringgrid. The input is unacceptable.

You can obtain the selected cell in the ondblclick event. Then, the input dialog box is displayed to accept user input, and then rewrite the value of cells [I, j]. Finally, you can control the SQL statement by using the program when submitting the database.

Whether to input data or use DBGrid,
Alternatively, you can open another edit window. When you click a cell in stringgrid, send the cell value to the edit window, modify it in the edit window, and save it to the database, echo again.

Procedure tform15.stringgrid1selectcell (Sender: tobject; ACOl,
Arow: integer; var canselect: Boolean );
Begin
Stringgrid1.instancesize;
Edit1.text: = stringgrid1.cells [ACOl, Arow];
A: = ACOl;
B: = Arow;
End;


Echo operation: strtofloat (stringgrid1.cells [a, B]): = edit1.text; // A, B is a global variable.

Well, it tells you that fieldbyname cannot be displayed because fields and tstringgrid are not added to fields editor. In options, set goediting to true.

Procedure tsjxmzlr. button1click (Sender: tobject );
VaR
I: integer;
J: integer;
Begin
Adoq_sjz.close;
Adoq_sjz. SQL .clear;
Adoq_sjz. SQL .text: = 'select Phid, sjmc from hymcb where lxmc =: lxmc ';
Adoq_sjz.parameters.parambyname ('lxmc '). Value: = trim (cb_lx.text );
Adoq_sjz.open;

// Habits
Adoq_sjz. First;


For I: = 0 to ADOQ_sjz.RecordCount-1 do
Begin
Sg_sjz.cells [0, I]: = adoq_sjz.fieldbyname ('phid'). asstring;
Sg_sjz.cells [1, I]: = adoq_sjz.fieldbyname ('sjmc '). asstring;
Adoq_sjz.next;
End;
Adoq_sjz.close;
// The parameter ********************************** ******************
Query1.params. Clear;


Adoq_sjz. SQL .clear;
Adoq_sjz. SQL .text: = 'select SJD from sjb where BD =: BD ';
Adoq_sjz.parameters.parambyname ('sjd '). Value: = trim (cbb_bd.text );
Adoq_sjz.open;
For J: = 0 to ADOQ_sjz.RecordCount-1 do
Begin
Sg_sjz.cols [J]: = adoq_sjz.fieldbyname ('sjd '). astring; // the error message [Error] sjzlr is displayed. PAS (118): incompatible types: 'tstrings 'and 'string'
Adoq_sjz.next;
End;
End;

Tstring type. You need to create an instance.

Sg_sjz.cols [J]. Add (adoq_sjz.fieldbyname ('sjd '). astring)

But how does DBGrid implement this form of table input? I want to input it in this form! What should I do? Is there any direct support for such controls?

It would be too troublesome to input hundreds of data records as liu_yq says! So I hope you can help me!

The problem is why you must use stringgrid instead of DBGrid.
The stringgrid is used for non-editing purposes.

DBGrid is difficult to implement. I do not know if it can be implemented.
as the landlord did, data in a table field is used as a column, I don't know if it can be automatically updated through grid
for example:
Project 1 20 30 20 30
Project 2 20 30 10 30
Project 3 20 50 10 20
Project 4 54 30 90 10
assume that the data of the first cell is modified, the field may not be found in the generated SQL statement.
I have not tried this method. If it is feasible, I can use it as a nonsense, I also moved my stool to study.

This input method is more intuitive, because I saw it in a software, so I want to do this. If none of this works, can I use a third-party control? What kind of controls can be used? Have you ever used it? If yes, let me know ??

Set goediting in options of stringgrid to true.
For Table cells that you do not want to edit in the stringgrid1selectcell event
Set canselect to false

Sg_sjz.cols [0] [J]: = adoq_sjz.fieldbyname ('sjd '). asstring; // display the J rows in the first column

Thank you very much for teaching jsqth! I can achieve my ideas! Thank you for your guidance!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.