Another date/time question

Smee

Well-Known Member
Licensed User
Longtime User
i am trying to add a date and a time to 2 columns in a table but i keep getting an error my code looks like this

Command.CommandText = "SELECT COUNT(*) FROM Sales"
Reader.Value = Command.ExecuteReader
Reader.ReadNextRow
OrderNo=Reader.GetValue(0)
Reader.Close
OrderNo=OrderNo+1
VanNo=1
Price=1
Amount=Qty*Price
GST=0
OrderDate = Date(Now)
OrderTime= Date(Now)
data1$=CustCode

The CustCode is a string variable but the only way the code would accept it is if i changed it to data1$

like this the code is accepted
StblOrders.AddRow (OrderNo,VanNo,data1$,ProductCode,Qty,"","",Amount,GST,0)

like this it is not
StblOrders.AddRow (OrderNo,VanNo,data1$,ProductCode,Qty,OrderDate,OrderTime,Amount,GST,0)


Sub App_Start
DateFormat("dd-mm-yyyy")
TimeFormat("HH:mm:ss")
end sub

can anyone help?
i have tried using dateformat but that does not work either
thanks
 

derez

Expert
Licensed User
Longtime User
It would help if you tell us what error you get.
Until then - check why to use DATE(now) for both date and time :

OrderDate = Date(Now)
OrderTime= Date(Now)

for time use time(now).
 

Smee

Well-Known Member
Licensed User
Longtime User
Hi ,

Thanks for the reply,

I have tried time(now) but it does not make any difference. I have tried Date by itself and time by itself. The error message was the same.
That error message is;
"Input string was not in the correct format. I had to make every variable a blank string and then add them back in one at a time to see which one(s) were causing the problem. I'm glad i only had 9 variables to deal with.

It seems if i put any string except either "" or a number in the positions where a string should go then i get the error. So it seems that i am unable to put a string into the table
 
Last edited:

mjcoon

Well-Known Member
Licensed User
I didn't know that a "$" character was allowed in a variable name. This isn't the sort of Basic that has typed variables using the final character to denote type. Must read the Basic4PPC Help on variable names.

Also, each column in a table is declared as string or number and you haven't given us the table declaration. I can imagine using a single numeric column to keep combined time and date as raw ticks or perhaps divided by cTicksPerSecond.

Mike.
 

Smee

Well-Known Member
Licensed User
Longtime User
Hi,
I thought i read somewhere that i was able to do that. regardless it does not seem to like it anymore:sign0161:

this is how the tasble is initialised
command.CommandText="SELECT * FROM [Sales] WHERE CustCode='" _
& CustCode & "' AND Uploaded=0"
Command.ExecuteTable("StblOrders",0)
StblOrders.ColWidth("OrderNo") = 0
StblOrders.ColWidth("VanNo") = 0
StblOrders.ColWidth("CustCode") = 0
StblOrders.ColWidth("ProductCode") = 20
StblOrders.ColWidth("Qty") = 30
StblOrders.ColWidth("OrderDate") = 0
StblOrders.ColWidth("OrderTime") = 0
StblOrders.ColWidth("Amount") = 30
StblOrders.ColWidth("GST") = 30
StblOrders.ColWidth("Uploaded") = 0
Panel1.Visible=False
StxtProdCode.Focus

As i understand it the table is loaded with all fields from the database and then i hide unrequired columns. Is this not the correct way?:confused:
 

mjcoon

Well-Known Member
Licensed User
Hi Smee, you could be right because I have not used tables in such a serious manner. I imagine that the field types are being taken from your database.

I was referring to Help which says:

Adds a new column to a Table.
Each column can store either string data (letters and numbers) or numbers only.
To sort and filter data as numbers, column type must be cNumber.
Syntax: AddCol (Column Type, Column Name, Width [,Unique])
Column Type - cString or cNumber

It is essential to make a distinction, as it says, because tables can be sorted and if numbers are sorted as if they were strings you get silly answers, such as:

10
20
200
2000
21

But though it says you can store a number in a cell defined as string, hopefully not a non-numeric in a number cell.

Mike.
 

Smee

Well-Known Member
Licensed User
Longtime User
Part of the aim is to understand structure and correct syntax. I may also need the data but not allow a user to see it

Thanks for the input.

i guess what i really need is detailed help and examples and to know when to use a particular method over another method. this is getting off my original q but for instance should i save the table data by looping thru the rows one at a time or is there a way to save the whole table data with one command?

:sign0163:
 
Top