|
Offhand I know how to do it from the command prompt, soooo:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C sc stop dnscache";
process.StartInfo = startInfo;
process.Start();
Quick code cribbed from SO at c# - Run Command Prompt Commands - Stack Overflow[^]. Credit where it's due.
|
|
|
|
|
Many thanks, it works. I ask for one more question. (example, something like)
When I run my program, if the DNS Client = Enabled (button1.Enabled = false, button2.Enabled = true),
and if the DNS Client = Disabled (button1.Enabled = true, button2.Enabled = false)
Thanks.
|
|
|
|
|
|
|
Thank you. I thought the DNS Client. I set the wrong image. I apologize.
|
|
|
|
|
1448281492 is an Utc-Date (as a decimal?) now i will get these date as a date of my time zone.
Can you may help me?
|
|
|
|
|
|
Sascha Lefèvre wrote: DateTime-
Keep in mind that unfortunately, DateTime, ignores time zone.
One should not confuse that with, for example, assuming that it is the same as UTC, because that would be wrong.
One should strive to use DateTimeOffset instead.
|
|
|
|
|
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
|
|
|
|