|
it's not work !
i have a same error
|
|
|
|
|
Post the exact code you're trying to run, and the exact error message.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
using (var connection = new OdbcConnection(lc.Connexion_locale))
using (var command = new OdbcCommand("insert into thisdet2 values(cat,geo,etb,nobl,vend,fam,art,des,tare)", connection))
{
OdbcParameter cat = command.Parameters.Add("@cat", OdbcType.NVarChar);
OdbcParameter geo = command.Parameters.Add("@geo", OdbcType.NVarChar);
OdbcParameter etb = command.Parameters.Add("@etb", OdbcType.NVarChar);
OdbcParameter nobl = command.Parameters.Add("@nobl", OdbcType.NVarChar);
OdbcParameter vend = command.Parameters.Add("@vend", OdbcType.NVarChar);
OdbcParameter fam = command.Parameters.Add("@fam", OdbcType.NVarChar);
OdbcParameter art = command.Parameters.Add("@art", OdbcType.NVarChar);
OdbcParameter des = command.Parameters.Add("@des", OdbcType.NVarChar);
OdbcParameter tare = command.Parameters.Add("@tare", OdbcType.NVarChar);
connection.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
OdbcParameter row = dataGridView1.Rows[i];
cat = row.Cells[0].Value;
geo = row.Cells[1].Value;
etb = row.Cells[2].Value;
nobl = row.Cells[3].Value;
vend = row.Cells[4].Value;
fam = row.Cells[5].Value;
art = row.Cells[6].Value;
des = row.Cells[7].Value;
tare = row.Cells[8].Value;
command.ExecuteNonQuery();
}
}
|
|
|
|
|
I notice you haven't posted the error message.
The first and most obvious problem with that code is that you've replaced the parameter placeholders - ? in the query I posted - with what appears to be column names. That won't work.
The query needs to be:
using (var command = new OdbcCommand("insert into thisdet2 values(?,?,?,?,?,?,?,?,?)", connection))
You should preferably specify the column names explicitly. Assuming the names you used are the column names:
using (var command = new OdbcCommand("insert into thisdet2 (cat,geo,etb,nobl,vend,fam,art,des,tare) values(?,?,?,?,?,?,?,?,?)", connection))
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i have try with '?' but its not work
|
|
|
|
|
And the error message is?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
the same :
Error 1 Can not implicitly convert type 'object ' to ' System.Data.Odbc.OdbcParameter ' . An explicit conversion exists ( cast he is missing ? )
|
|
|
|
|
the same :
Error 1 Can not implicitly convert type 'object ' to ' System.Data.Odbc.OdbcParameter ' . An explicit conversion exists ( cast he is missing ? )
|
|
|
|
|
Your code should look like this:
using (OdbcConnection connection = new OdbcConnection(lc.Connexion_locale))
using (OdbcCommand command = new OdbcCommand("insert into thisdet2 (cat,geo,etb,nobl,vend,fam,art,des,tare) values (?,?,?,?,?,?,?,?,?)", connection))
{
OdbcParameter cat = command.Parameters.Add("@cat", OdbcType.NVarChar);
OdbcParameter geo = command.Parameters.Add("@geo", OdbcType.NVarChar);
OdbcParameter etb = command.Parameters.Add("@etb", OdbcType.NVarChar);
OdbcParameter nobl = command.Parameters.Add("@nobl", OdbcType.NVarChar);
OdbcParameter vend = command.Parameters.Add("@vend", OdbcType.NVarChar);
OdbcParameter fam = command.Parameters.Add("@fam", OdbcType.NVarChar);
OdbcParameter art = command.Parameters.Add("@art", OdbcType.NVarChar);
OdbcParameter des = command.Parameters.Add("@des", OdbcType.NVarChar);
OdbcParameter tare = command.Parameters.Add("@tare", OdbcType.NVarChar);
connection.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
DataGridViewRow row = dataGridView1.Rows[i];
cat.Value = row.Cells[0].Value;
geo.Value = row.Cells[1].Value;
etb.Value = row.Cells[2].Value;
nobl.Value = row.Cells[3].Value;
vend.Value = row.Cells[4].Value;
fam.Value = row.Cells[5].Value;
art.Value = row.Cells[6].Value;
des.Value = row.Cells[7].Value;
tare.Value = row.Cells[8].Value;
command.ExecuteNonQuery();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
it works
but I do not understand why your put ????? .
thank you
|
|
|
|
|
? is the parameter placeholder for the OdbcCommand and OleDbCommand classes.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Based on what I've seen so far, I would suggest "baby steps".
Start with one "row" and one "cell" / column.
Display the contents of that first cell before attempting to insert it into the database to see if you are actually getting what you're expecting.
Then try a database insert.
When that works, retrieve a few more cells; then a few more rows; etc.
I would also check your "for" loop ... it looks like you are retrieving one less row than there are actual rows (the "while" for a "zero-based" index is "index < count"; not "index < count - 1").
And since "cells" are also a collection, it may be possible to iterate over them in at least some of your code instead of referencing each one of them directly.
|
|
|
|
|
Hello once again!
I have been trying to get global hotkeys to work in order for my program to write out certain lines of text without having the form in focus, but I cannot figure out how to use the hook properly.
I'm trying to use this
Processing Global Mouse and Keyboard Hooks in C#[^]
For example, I want my program to send the code of a button when pressing Alt+T. How could I use the code for this?
|
|
|
|
|
You should post your question in the forum at the end of the article, and explain exactly what problems you are having.
|
|
|
|
|
Thanks, did not realize this.
Done and done.
|
|
|
|
|
Linus Agren wrote: How could I use the code for this? By extracting the hook portion, and adapting it to send some keys to the active window on a predefined combination.
Linus Agren wrote: but I cannot figure out how to use the hook properly. Does the example work?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I tried using the example and adding the UserActivityHook to my project, however, I cannot use it in my form for some reason.
I get this typical error:
Error 1 The type or namespace name 'UserActivityHook' could not be found (are you missing a using directive or an assembly reference?)
I've searched for hours and cannot find what I forgot to do.
|
|
|
|
|
You are missing the reference to the project. Go to the solution-explorer, rightclick on the "references" node, and click "add".
Also see MSDN[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have used the code from the CP article by Mamaladze you cite successfully for Global Hooking with Visual Studio 2013, compiling against FrameWork 4.5.1., and it's now running okay in Visual Studio 2015 CTP 5 compiled against FrameWork 4.6.
Note, however, that I have taken Mamaladze's source code, copied it, hacked out the 'Global bits, and the 'Mouse hook bits, and then re-compiled it. So I'm using it as an Application level Hook only, and only trapping Keyboard entries.
Reality check:
1. Your project (I'm assuming WinForms) should reference to 'MouseKeyboardActivityMonitor dll
2. The Form that instantiates the Hook should have Using statements that look like this:
using MouseKeyboardActivityMonitor;
using MouseKeyboardActivityMonitor.WinApi;
This is what working code in my "test-bed" looks like for the MainForm:
using System;
using System.Windows.Forms;
using MouseKeyboardActivityMonitor;
using MouseKeyboardActivityMonitor.WinApi;
namespace Test_Mama_HotKey
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
m_KeyboardHookManager = new KeyboardHookListener(new AppHooker());
m_KeyboardHookManager.Enabled = true;
m_KeyboardHookManager.KeyDown += HookManager_KeyDown;
}
private readonly KeyboardHookListener m_KeyboardHookManager;
private void HookManager_KeyDown(object sender, KeyEventArgs e)
{
Log(string.Format("{0} {1} {2}", ActiveForm.Text, ActiveForm.ActiveControl.Name, e.KeyData));
}
private void Log(string text)
{
textBox1.AppendText(string.Format("{0}{1}", text, Environment.NewLine));
}
}
} Edit: After exploring Toub's HotKey implementation more deeply, I have come to the decision not to use it.
I am currently experimenting with using the Hook code in this article by Toub: [^] to install an Application (not Global) wide HotKey hook in Visual Studio 2015 CTP 6 compiled against FrameWork 4.6. I've essentially taken out his code which does the "Global" bit, and taken out his mouse-hook code, since I just want the low-level keyboard hook; it compiles okay, now, but is not fully tested.
End Edit.
The best advice I can give you is to study Mamaladze's working example and figure out what is missing from your code, or what you are not instantiating, or using, in your code.
With your adapted Mamaladze hook code now: does it compile ? Are there any specific errors at run-time. What, exactly, does not work ?
«I'm asked why doesn't C# implement feature X all the time. The answer's always the same: because no one ever designed, specified, implemented, tested, documented, shipped that feature. All six of those things are necessary to make a feature happen. They all cost huge amounts of time, effort and money.» Eric Lippert, Microsoft, 2009
modified 25-Feb-15 4:52am.
|
|
|
|
|
This morning one of the users showed me an error (in an application I didn't write, but did modify) where a generated (file)path resulted in yyyy-MM instead of yyyy/MM . The error was of course that the file could not be found.
We solved it (or worked around it) by changing his regional settings. So I went back to the code where the log of the erroneous path was generated and found this:
string serverpath = Utilities.Settings.Setting["drawingpath"] + "/" +
D.DateTime.ToString("yyyy/MM") + "/" +
D.Prefix +
D.DateTime.ToString("yyyyMMddHHmm") + ".jpg";
string localpath = Utilities.Settings.Setting["drawingtemppath"] + "/" +
D.DateTime.ToString("yyyy/MM") + "/" +
D.Prefix +
D.DateTime.ToString("yyyyMMddHHmm") + ".jpg";
System.IO.Directory.CreateDirectory(Utilities.Settings.Setting["drawingtemppath"] + "/" + D.DateTime.ToString("yyyy/MM"));
try{
System.IO.File.Copy(serverpath, localpath, true);
}
catch(Exception ex){
string msg = "DSGUI_BulkAnalyze().goByStats(): Error:["+ex.Message+"]";
Utilities.Logger.WriteLog(Utilities.Logger.TYPE.ERROR, Utilities.Logger.ACTION.SYSTEM, Utilities.Logger.SEVERITY.HIGH, msg);
}
}
The error is thrown by the serverpath variable, but I'm confused how it generates yyyy-MM instead of yyyy/MM and how the regional settings of the machine are involved.
Anyone any idea?
I know it is the serverpath variable because of the "C:\archdrawings_dev" part of the path.
Here's an example of one of the logs:
DSGUI_BulkAnalyze().goByStats(): Error:[Could not find a part of the path 'C:\archdrawings_dev/2011-04/usd201104270615.jpg'.]
thanks.
|
|
|
|
|
Try
D.DateTime.ToString("yyyy") + "/" + D.DateTime.ToString("MM") instead of
D.DateTime.ToString("yyyy/MM") My guess is that as you are formatting the date as a string something may be getting replaced in the process(I know that's a very vague statement).
By trying what I suggest you will be ruling out that possibility.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
When you specify the date format, "/" does not mean "insert a slash", any more than "yyyy" means "insert four 'y's" - it means "insert the current culture date separator character": MSDN[^]
If you absolutely want a specific character, escape it:
string serverpath = Utilities.Settings.Setting["drawingpath"] + "/" +
D.DateTime.ToString("yyyy\\/MM") + "/" +
D.Prefix +
D.DateTime.ToString("yyyyMMddHHmm") + ".jpg"; (Remembering to escape the escape character or it'll be "swallowed" by the compiler - but you know that!)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I would have never thought of that. The fact that "/" is often set as the separator only adds to the confusion. I will try this asap.
|
|
|
|
|
Very good.
Regards,
Rob Philpott.
|
|
|
|
|
It is generally not the best idea to leave your code to default to regional settings when you are expecting something specific from your results, as you are in this case. You can tell .net to use a specific culture when you do your ToString and you always get the format of that culture.
DateTime.Now.ToString("yyyy/MM", CultureInfo.CreateSpecificCulture("en-GB"));
However given you want a literal slash due to you creating a file path you're better with the escaping example provided in other post as that makes it unambiguous that you need a literal slash, ie for a path.
|
|
|
|
|