|
If those are the number of ticks, then it would be januari the first of your epoch year
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You need to know what the number is. Its possible that the number is the number of ticks, and if so, see the answers above. It could also be a Unix timestamp or a Julian Day number, in which case see my tip here[^]
|
|
|
|
|
Where is this data coming from?
It might actually be a C++ time_t date (seconds since midnight 1970).
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
THANKS!
I get it!
item.CreationDate is a value from a database: it's the utcDate
so now I have this code:
string einstellDatumTemp = item.creationDate.ToString();
int unixTimestamp = int.Parse(einstellDatumTemp);
DateTime unixYear0 = new DateTime(1970, 1, 1);
long unixTimeStampInTicks = unixTimestamp * TimeSpan.TicksPerSecond;
DateTime dtUnix = new DateTime(unixYear0.Ticks + unixTimeStampInTicks);
|
|
|
|
|
The number looks to me like a standard Windows Time value and equates to the UTC time 12:24:52 Mon Nov 23 2015. You can use any of the standard .NET DateTime methods to display it as local time, according to your timezone.
|
|
|
|
|
Member 11916735 wrote: as a date of my time zone.
Better be very sure that it is your time zone.
Good to go if that number is being generated by your computer. But if is coming from another source (computer, database, etc) then you need to determine that.
|
|
|
|
|
Hello Eerry Body,
I'm working on an application in C # which allows to upgrade a Postgresql database to another database.
here is my code
namespace insert
{
class Program
{
static void Main(string[] args)
{
string connString = "DSN=pg_prd;Database=RPD;User Id=postgres;Password=*****;";
OdbcConnection conn = new OdbcConnection(connString);
OdbcCommand command = conn.CreateCommand();
command.CommandText = "Select etb,nobl,poidsb from t_thisdet";
conn.Open();
OdbcDataAdapter MyAdapter = new OdbcDataAdapter();
MyAdapter.SelectCommand = command;
DataSet dset = new DataSet("t_thisdet");
DataTable ds1 = new DataTable("ds1");
MyAdapter.Fill(ds1);
conn.Close();
string conn1String = "DSN=testing;Database=RPD;User Id=postgres;Password=****;";
OdbcConnection conn1 = new OdbcConnection(conn1String);
OdbcCommand command2 = conn1.CreateCommand();
conn1.Open();
for (int k = 1; k < ds1.Rows.Count; k++)
{
string etb= ds1.Rows[k][@"etb"].ToString();
string nobl = ds1.Rows[k][@"nobl"].ToString();
string poidsb = ds1.Rows[k][@"poidsb"].ToString();
command2.CommandText="insert into hisdet values ('"+etb+"',"+nobl+","+poidsb+")";
command2.ExecuteNonQuery();
}
conn1.Close();
}
When I run my code I have this error :
System.Data.Odbc.OdbcException: ERROR [42601] ERROR: INSERT has more expressions than target columns;
Error while executing the query.
While the structure of the select query is equal to the structure of the inserte request.
you have some idea about this.
thank you for your help.
|
|
|
|
|
what is the db schema/structure for 'hisdet' ?
it looks like what you are trying to do is insert a row into hisdet, that has 2 columns, but you are supplying 3 values - its not a good way to build a command by the way - you should be using a parameterised statement rather than building it from scratch
Im also worried that the values in your insert statement are inconsistently quoted anyway - why the single outer and then double inner quotes around +etb+ ?
|
|
|
|
|
structure of hisdet :
etb character varying(2),
nobl numeric,
poidsb numeric
hisdet contains 3 columns like select request.
|
|
|
|
|
Depends on the content of the fields - you should never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
The chances are that will fix your problem.
And while you are at it, it's a bad idea to use INSERT INTO without listing the columns you want to insert into. If you don't, then it always tries to insert from left to right, which may not be the order if changes are made to your DB.
command2.CommandText="INSERT INTO hisdet (etb, nobl, poidsb) VALUES (@E, @N, @P)";
command2.Parameters.AddWithValue("@E", etb);
command2.Parameters.AddWithValue("@N", nobl);
command2.Parameters.AddWithValue("@P", poidsb);
command2.ExecuteNonQuery();
If that doesn't fix it, then check your destination table and make sure you created all three columns.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
thank you for your answer.
i have trying your code but i have another error :
System.Data.Odbc.OdbcException: ERROR [42703] ERROR: column "e" does not exist;
|
|
|
|
|
Check your code: it looks like you copied it wrong!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
For an OdbcCommand , you can't use named parameters. You have to use positional parameters instead:
command2.CommandText="INSERT INTO hisdet (etb, nobl, poidsb) VALUES (?, ?, ?)";
command2.Parameters.AddWithValue("@E", etb);
command2.Parameters.AddWithValue("@N", nobl);
command2.Parameters.AddWithValue("@P", poidsb);
command2.ExecuteNonQuery();
OdbcCommand.Parameters Property (System.Data.Odbc)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you.
But i have an other error :
invalid input syntax for type numeric : "5.5";
|
|
|
|
|
One of your columns is expecting a numeric value, and you're passing in a string. PostgreSql cannot convert the string you've passed in to a numeric value, possibly due to the regional settings.
Convert the values to the correct type before passing them to the AddWithValue method. For a numeric type, use Double.TryParse[^] to convert the string to a number.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
like this :
command2.Parameters.double.tryparse.AddWithValue
?
|
|
|
|
|
No, that's not how you write code in C#!
Try this:
const string SourceConnectionString = "DSN=pg_prd;Database=RPD;User Id=postgres;Password=*****;";
const string DestinationConnectionString = "DSN=testing;Database=RPD;User Id=postgres;Password=****;";
DataTable ds1 = new DataTable("ds1");
using (OdbcConnection conn = new OdbcConnection(SourceConnectionString))
using (OdbcCommand command = conn.CreateCommand())
{
command.CommandText = "Select etb,nobl,poidsb from t_thisdet";
OdbcDataAdapter MyAdapter = new OdbcDataAdapter(command);
MyAdapter.Fill(ds1);
}
using (OdbcConnection conn = new OdbcConnection(DestinationConnectionString))
using (OdbcCommand command = conn.CreateCommand())
{
command.CommandText="INSERT INTO hisdet (etb, nobl, poidsb) VALUES (?, ?, ?)";
conn.Open();
foreach (DataRow row in ds1.Rows)
{
command.Parameters.AddWithValue("etb", row["etb"]);
command.Parameters.AddWithValue("nobl", row["nobl"]);
command.Parameters.AddWithValue("poidsb", row["poidsb"]);
command.ExecuteNonQuery();
command.Parameters.Clear();
}
}
The columns in your DataTable are probably already the correct type. You just need to pass the value to the parameter, without converting the value to a string first.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i have trying your code but i have always the same error :
System.Data.Odbc.OdbcException: ERROR [22P02] ERROR: invalid input syntax for type numeric: "1,58";
|
|
|
|
|
Then the schemas of the tables don't match, and the data from the source table cannot automatically be converted to the expected type for the destination table.
Your previous error message was trying to convert the value "5.5", but this message is trying to convert the value "1,58". (Note the different decimal separators - "." versus "," .) Are you storing numbers as strings, using client-specific formatting? If so, you'll struggle to convert the data cleanly, as there's no way to know which row uses which format.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
in the table hisdet :
etb : varchar
nobl and poidsb is numeric.
I can't convert recovered line value to numeric
|
|
|
|
|
is what you have ideas how to convert string to numeric in my code ?
|
|
|
|
|
If the string has a consistent format, then use Double.TryParse[^] to convert the string:
string inputValue = "5.5";
double numericValue;
if (double.TryParse(inputValue, NumberStyles.Any, CultureInfo.InvariantCulture, out numericValue))
{
}
else
{
}
If the format is not consistent, then you'll need to clean up the source data by hand.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
the format is consistent in the database but I can't get a place double.tryparse in my code.
|
|
|
|
|
it's work it was necessary to add the line for format :
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
|
|
|
|
Hi,
I am having a problem in putting a marker for every location in my bing map, this is my code:
private async void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
await
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
async () =>
{
UriString4 = "my URL";
var http = new HttpClient();
http.MaxResponseContentBufferSize = Int32.MaxValue;
var response = await http.GetStringAsync(UriString4);
var rootObject = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);
Location[] location = new Location[int.Parse(rootObject.total)];
for (int i = 0; i < int.Parse(rootObject.total); i++)
{
location[i] = new Location(rootObject.locals[i].local_latit,rootObject.locals[i].local_longi);
MapLayer.SetPosition(GpsIcon, location[i]);
GpsIcon.SetRadius(args.Position.Coordinate.Accuracy);
GpsIcon.Visibility = Windows.UI.Xaml.Visibility.Visible;
MyMap.SetView(location[i], 17);
}
}));}
This is the JSON data from where I want to get the local_longi and local_latit of every Location:
{
success : 1,
total : 2,
locals : [{
id_local : "59",
local_longi : "20",
local_latit : "25894"
}, {
id_local : "60",
local_longi : "10.33699",
local_latit : "25.997745"
}
]
}
The problem is that I get only one marker on the map,
from the Debugger,I get all results in "location" variable,I don't know why I get only one marker in the Map
Please How can I correct my code to have multiple Locations set in the Map
thanks for help
|
|
|
|