|
Ibrahim.elh wrote: does not include visual studio .cells []
Sorry, I don't understand that comment.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I tested your code but I have an error
row.Cells[0].Value
cell is not included!!!
|
|
|
|
|
OK, that's closer, but it's still not clear. What's 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
|
|
|
|
|
Error 1 'object' does not contain a definition for ' Cells ' and no extension method ' Cells ' accepting a first argument of type 'object' was found ( a using directive or is an assembly reference ? missing)
|
|
|
|
|
That doesn't sound right - the Rows[i] indexer is supposed to return a DataGridViewRow , not an object .
Try replacing:
var row = dataGridView1.Rows[i];
with:
DataGridViewRow row = dataGridView1.Rows[i];
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Not work !
Error 1 Can not implicitly convert type 'object ' to ' System.Data.Odbc.OdbcParameter ' . An explicit conversion exists ( cast he is missing ? )
|
|
|
|
|
Once again, command.Parameters.Add(...) returns an OdbcParameter , not an object , so var p0 = command.Parameters.Add(...) should work.
If you were using an older version of .NET which didn't support var , you'd be getting a different error message.
Try specifying the types explicitly - for all of the lines:
var pN = command.Parameters.Add(...);
replace var with OdbcParameter :
OdbcParameter pN = command.Parameters.Add(...);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
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[^]
|
|
|
|
|