Click here to Skip to main content
15,877,360 members
Home / Discussions / C#
   

C#

 
GeneralRe: Insert the data of datagridview in a database. Pin
Richard Deeming25-Feb-15 4:08
mveRichard Deeming25-Feb-15 4:08 
GeneralRe: Insert the data of datagridview in a database. Pin
Ibrahim.elh25-Feb-15 4:11
Ibrahim.elh25-Feb-15 4:11 
GeneralRe: Insert the data of datagridview in a database. Pin
Richard Deeming25-Feb-15 4:25
mveRichard Deeming25-Feb-15 4:25 
GeneralRe: Insert the data of datagridview in a database. Pin
Ibrahim.elh25-Feb-15 4:31
Ibrahim.elh25-Feb-15 4:31 
GeneralRe: Insert the data of datagridview in a database. Pin
Richard Deeming25-Feb-15 4:41
mveRichard Deeming25-Feb-15 4:41 
GeneralRe: Insert the data of datagridview in a database. Pin
Ibrahim.elh25-Feb-15 4:47
Ibrahim.elh25-Feb-15 4:47 
GeneralRe: Insert the data of datagridview in a database(error). Pin
Ibrahim.elh25-Feb-15 4:48
Ibrahim.elh25-Feb-15 4:48 
GeneralRe: Insert the data of datagridview in a database(error). Pin
Richard Deeming25-Feb-15 4:54
mveRichard Deeming25-Feb-15 4:54 
Your code should look like this:
C#
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))
{
    // ODBC doesn't use named parameters, so the names don't matter:

    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


GeneralRe: Insert the data of datagridview in a database(error). Pin
Ibrahim.elh25-Feb-15 23:30
Ibrahim.elh25-Feb-15 23:30 
GeneralRe: Insert the data of datagridview in a database(error). Pin
Richard Deeming26-Feb-15 1:06
mveRichard Deeming26-Feb-15 1:06 
AnswerRe: Insert the data of datagridview in a database. Pin
Gerry Schmitz25-Feb-15 23:37
mveGerry Schmitz25-Feb-15 23:37 
QuestionGlobal Hotkeys? Pin
Linus Agren24-Feb-15 4:57
Linus Agren24-Feb-15 4:57 
SuggestionRe: Global Hotkeys? Pin
Richard MacCutchan24-Feb-15 5:41
mveRichard MacCutchan24-Feb-15 5:41 
GeneralRe: Global Hotkeys? Pin
Linus Agren24-Feb-15 5:56
Linus Agren24-Feb-15 5:56 
AnswerRe: Global Hotkeys? Pin
Eddy Vluggen24-Feb-15 7:19
professionalEddy Vluggen24-Feb-15 7:19 
QuestionRe: Global Hotkeys? Pin
Linus Agren24-Feb-15 16:59
Linus Agren24-Feb-15 16:59 
AnswerRe: Global Hotkeys? Pin
Eddy Vluggen25-Feb-15 0:30
professionalEddy Vluggen25-Feb-15 0:30 
AnswerRe: Global Hotkeys? Pin
BillWoodruff24-Feb-15 19:51
professionalBillWoodruff24-Feb-15 19:51 
QuestionDateTime ToString [confused] Pin
V.24-Feb-15 2:19
professionalV.24-Feb-15 2:19 
AnswerRe: DateTime ToString [confused] Pin
GuyThiebaut24-Feb-15 2:43
professionalGuyThiebaut24-Feb-15 2:43 
AnswerRe: DateTime ToString [confused] PinPopular
OriginalGriff24-Feb-15 2:43
mveOriginalGriff24-Feb-15 2:43 
GeneralRe: DateTime ToString [confused] Pin
V.24-Feb-15 2:51
professionalV.24-Feb-15 2:51 
GeneralRe: DateTime ToString [confused] Pin
Rob Philpott24-Feb-15 2:57
Rob Philpott24-Feb-15 2:57 
AnswerRe: DateTime ToString [confused] Pin
F-ES Sitecore24-Feb-15 3:33
professionalF-ES Sitecore24-Feb-15 3:33 
AnswerRe: DateTime ToString [confused] Pin
Daniel Pfeffer25-Feb-15 2:54
professionalDaniel Pfeffer25-Feb-15 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.