Delphi DB question

Forum: ProgrammersTotal Replies: 6
Author Content
J_Maxwell

Oct 21, 2002
5:02 PM
Hello!

I am a little new with the database stuff, so here goes. I am trying to add a line to two columns of a dxMemData, named datas. I have a TDataSource connected to the dxMemData, named DataSource1, in which I have AutoEdit and Enabled set to true. Regardless of how much I hard-code the properties, I always get this error: "datas: Dataset not in edit or insert mode."


Here is the code that I am using:

i := addform.ShowModal;
item := addform.edit1.text;
quantity := addform.edit2.text;
with datas do begin
DelimiterChar := ',';
if NOT active then
Open;
if Locate('RecID', 0, []) then begin
edit;
end
else begin
append;
end;

datasource1.Enabled := true;
datasource1.AutoEdit := true;
datasource1.edit;
FieldByName('item').AsString := item;
FieldByName('quantity').AsString := quantity;
post;
end;
end;

Any ideas?

J_Maxwell

PS I think that it is a problem with the datasource because I have taken the DataSet field out, and I don't get the error message.
DaveKlein

Oct 21, 2002
8:51 PM
I think you're right. In the scenario you described you don't need a datasource. Datasources are only used for connecting data aware components to a dataset. If you are working with your dataset directly in code you don't need it. It shouldn't hurt to have it, but you don't need to do anything to it in your code. The code you show above really should work fine if you take out lines that deal with the datasource.

There are often times when you need to have a TDatasource to connect to visual controls but you also want to access the dataset directly. You should be able to do that. If you keep having problems with that post again.
J_Maxwell

Oct 21, 2002
9:05 PM
Thanks for the reply. I took out all the code (to the dataset) and it still doesn't work. I am just trying to connect the dxMemData component to the reportview component. It loads just fine, I just want it to add an item to the report view. I thought that this would be the best way, so that I have the reportview and the memdata component sync'ed up.

I have tried this code, I took out all references to the Dataset:

with datas do begin
DelimiterChar := ',';
if NOT active then
Open;
append;
FieldByName('item').AsString := item;
FieldByName('quantity').AsString := quantity;
post;
end;

Any ideas? I have tried lots more things, but the closest I could come was to be able to load it and then add lines, but even then I was having a problem. In the report view, it would only allow a certian amount of lines, and then it would delete an item.

Thanks,

J_Maxwell
J_Maxwell

Oct 23, 2002
3:12 PM
I just found out something else. If I do:

mainform.datas.edit;//datas being the TdxMemData

it will keep over-writing the last line of the reportview. I have tried:

mainform.datas.append;
mainform.datas.edit;
mainform.datas.append;

but I keep getting the error:

datas: Dataset not in edit or insert mode.

Also, I tried this:
mainform.datas.FieldValues['item'] := item;
mainform.datas.FieldValues['quantity'] := quantity;

instead of the code above, and that seems to get me somewhere further. I am also calling the post method.

ANy ideas?

Thanks for the help,

J_Maxwell
DaveKlein

Oct 24, 2002
7:43 AM
I haven't had a chance to experiment with this scenario, but one thought occurred ot me. You mentioned earlier that if you take the Dataset out of the Datasource component then it worked. If that's the case then how about setting that at runtime. Before your code that adds data to the dataset, add in a line like this: datasource1.Dataset := ''; and then after you have added your data put in a line like this: datasource1.Dataset := datas;

Give that a try and I will try to do some looking into this tonight.
J_Maxwell

Oct 24, 2002
3:47 PM
Well, that could work, but I have the TOvcDBReportView hooked up to the datasource, which the supplies the column list with the contents for the columns, so I don't think that'll work. I tried it, but I got a huge amount of access violations, maybe because of no data going to the report view?

Thanks for the help,

J_Maxwell
J_Maxwell

Oct 29, 2002
4:54 PM
Hello!

I tracked this thing down and I think that it is the report view. Here are the steps that I used. I first selected the datasource. Then, I went into the views property, and created a view named, MasterList2003, and it's title, MasterList 2003. Then I double-clicked the property. I then added a field and specified in the fieldname property from the drop-down list. I did the same for the next column as well. Finally I set the active view to the one I just created.

I looked in help, and found how to do it, but, it still doesn't work. I don't think that I am missing anything, but am I?

Thanks,

J_Maxwell

Posting in this forum is limited to members of the group: SITEADMINS, SUBSCRIBERS, MEMBERS.]

the Open Forums!

  Login
If you don't have an account yet, visit the registration page to sign up.

If you already have an account, you may login here:

Username: Password:

  Welcome to the Open Forums!!
Welcome to the Open Forums!!

  Hosted By...

This website is hosted by:

 -
PreparingSons
 - Titus2.com


[ Copyright © the Open Forums! | All times are recorded in ET ]

[ Contact Us ]

Login

Powered by Scif 5.3 build 285 by StandardOut, Inc.