|
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
|
|
|
|
|
Hi Friends
I am creating a PoC in windows MDM. I gone through the below link and understand the flow of the MDM.
I create a sample OMA Client Provisioning File(WAP format) and i need to update this Provisioning data(XML) into CSP to support OMA Device Management Command(SyncML).
I try to create C# code(ConfigurationManager.ProcessConfiguration Method (Microsoft.WindowsMobile.Configuration)[^]). Not able to find this library( microsoft.windowsmobile.configuration.dll). As an alternate I create VC++ based on below link()[Device_Management DMProcessConfigXMLFiltered">^]
I am getting Error like (
HRESULT - 0x80010106 - Cannot change thread mode after it is set.
).
I need help on reading the WAP provisioning XML and set it to registry or CSP in windows 10.
Your help is appreciated. Thanks
|
|
|
|
|
The is a continuation from the last question I had in implementing WeakEvents. I am able to add a handler to INotifyPropertyChange property using reflection, and also check if it exists within the class:
MethodInfo addHandlerMethod = SendOrListenType.GetMethod("AddHandler");
if (typeof(INotifyPropertyChanged).IsAssignableFrom(_WeakBoundObject.Target.GetType()))
addHandlerMethod.Invoke(null, new object[] { _WeakBoundObject.Target, "PropertyChanged", handler });
My problem arises when I wanted to add WeakHandlers to an ObservableCollection. I am able to find the event CollectionChanged:
EventInfo er = _WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType.GetEvent("CollectionChanged");
And Im also able to check if it exists:
if (typeof(INotifyCollectionChanged).IsAssignableFrom(_WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType))
but this refuses to compile:
addHandlerMethod.Invoke(null, new object[] {_WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType, "CollectionChanged", handler });
I have tried loads of different alternatives, but I can find the right one, can anyone spot my mistake here?
[Edit]
I have also changed the code to initialize the WeakEventMAnager:
Type unboundWEMType = typeof(WeakEventManager<,>);
Type[] typeArgs = { typeof(ObservableCollection<string>) , typeof(EventArgs) };
Type TempSendOrListenType = unboundWEMType.MakeGenericType(typeArgs);
MethodInfo addHandlerMethod2 = TempSendOrListenType.GetMethod("AddHandler");
if (typeof(INotifyCollectionChanged).IsAssignableFrom(_WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType))
addHandlerMethod2.Invoke(null, new object[] {_WeakBoundObject.Target.GetType().GetProperty(PropertyName), "CollectionChanged", handler });
Stack trace:
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code
Additional information: Object of type 'System.Reflection.RuntimePropertyInfo' cannot be converted to type 'System.Collections.ObjectModel.ObservableCollection`1[System.String]'.
modified 27-Jan-16 13:12pm.
|
|
|
|
|
It looks like you need to pass the property value to the AddHandler method, rather than the property type or the PropertyInfo .
Try:
addHandlerMethod2.Invoke(null, new object[] {_WeakBoundObject.Target.GetType().GetProperty(PropertyName).GetValue(_WeakBoundObject.Target), "CollectionChanged", handler });
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, it works. It's very useful , but I hate reflection
|
|
|
|
|
Kenneth Haugland wrote: but I hate reflection Why, I know it may be a funny for you but I'm curious to the background to the attitude.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I might not have been very precise here. I hate the way that it is set up. They seem to work like pointers that doesn't point in the direction I think they are. I think I have the right values, but then I don't, it turns my hairs grey.
|
|
|
|
|
I can't claim to deeply understand these two posts, but their "depth," and the fascinating responses, get my up-votes
If you have time/inclination to say something about the context in this scenario that leads you to need to compose executable code, and modify objects, that would be very interesting.
thanks, Bill
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
|
I'm following this example[^]
Here's my code:
using System.Collections.Generic;
using EnvDTE;
namespace MyApp
{
public class IISDebugAttach
{
public void AttachToIIS()
{
bool attached = false;
List<string> listProcess = new List<string>();
listProcess.Add("aspnet_wp.exe");
listProcess.Add("w3wp.exe");
listProcess.Add("webdev.webserver.exe");
foreach (Process process in DTE.Debugger.LocalProcesses)
{
foreach (var processName in listProcess)
{
if (process.Name.ToLower().IndexOf(processName) != -1)
{
process.Attach();
}
}
}
}
}
}
I get a compilation error on the first FOREACh saying "An object reference is required for the non-static field, method, or property '_DTE.Debugger'"
What am I doing wrong here???
If it's not broken, fix it until it is
|
|
|
|
|
DTE is a class, but Debugger is not a static property - you want the instance that is passed in as the method parameter in the example:
public static void LocalProcesses(DTE dte)
{
...
EnvDTE.Processes processes = dte.Debugger.LocalProcesses;
I've not tried any of this - never had the need - but does this help: HOWTO: Get an EnvDTE.DTE instance from a Visual Studio package[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: you want the instance that is passed in as the method parameter in the example:
What parameter? What example are you referring to? The example I quoted has no param being passed in. Where do you see ...void LocalProcesses(DTE dte)?
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: What parameter? What example are you referring to?
The example you linked to...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I think I figured it out. I needed:
DTE dte = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.14.0");
If it's not broken, fix it until it is
|
|
|
|
|
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|