Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Application updated database. Pin
OriginalGriff28-Jan-16 0:45
mveOriginalGriff28-Jan-16 0:45 
GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 1:13
Ibrahim.elh28-Jan-16 1:13 
GeneralRe: C# Application updated database. Pin
OriginalGriff28-Jan-16 1:24
mveOriginalGriff28-Jan-16 1:24 
GeneralRe: C# Application updated database. Pin
Richard Deeming28-Jan-16 1:29
mveRichard Deeming28-Jan-16 1:29 
GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 1:36
Ibrahim.elh28-Jan-16 1:36 
GeneralRe: C# Application updated database. Pin
Richard Deeming28-Jan-16 1:39
mveRichard Deeming28-Jan-16 1:39 
GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 1:57
Ibrahim.elh28-Jan-16 1:57 
GeneralRe: C# Application updated database. Pin
Richard Deeming28-Jan-16 2:06
mveRichard Deeming28-Jan-16 2:06 
No, that's not how you write code in C#! D'Oh! | :doh:

Try this:
C#
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


GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 2:29
Ibrahim.elh28-Jan-16 2:29 
GeneralRe: C# Application updated database. Pin
Richard Deeming28-Jan-16 2:34
mveRichard Deeming28-Jan-16 2:34 
GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 3:19
Ibrahim.elh28-Jan-16 3:19 
GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 4:15
Ibrahim.elh28-Jan-16 4:15 
GeneralRe: C# Application updated database. Pin
Richard Deeming28-Jan-16 4:21
mveRichard Deeming28-Jan-16 4:21 
GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 4:34
Ibrahim.elh28-Jan-16 4:34 
GeneralRe: C# Application updated database. Pin
Ibrahim.elh28-Jan-16 5:41
Ibrahim.elh28-Jan-16 5:41 
Questionsetting multiple Locations in a bing Map Pin
yemen_mansour27-Jan-16 21:34
yemen_mansour27-Jan-16 21:34 
QuestionWindows 10 Mobile MDM - Device Provisioning Pin
gomes127-Jan-16 19:50
gomes127-Jan-16 19:50 
QuestionAdd WeakEvent to ObservableCollection using reflection Pin
Kenneth Haugland27-Jan-16 6:52
mvaKenneth Haugland27-Jan-16 6:52 
AnswerRe: Add WeakEvent to ObservableCollection using reflection Pin
Richard Deeming27-Jan-16 7:17
mveRichard Deeming27-Jan-16 7:17 
GeneralRe: Add WeakEvent to ObservableCollection using reflection Pin
Kenneth Haugland27-Jan-16 7:21
mvaKenneth Haugland27-Jan-16 7:21 
GeneralRe: Add WeakEvent to ObservableCollection using reflection Pin
Mycroft Holmes27-Jan-16 12:05
professionalMycroft Holmes27-Jan-16 12:05 
GeneralRe: Add WeakEvent to ObservableCollection using reflection Pin
Kenneth Haugland27-Jan-16 22:09
mvaKenneth Haugland27-Jan-16 22:09 
AnswerRe: Add WeakEvent to ObservableCollection using reflection Pin
BillWoodruff27-Jan-16 14:52
professionalBillWoodruff27-Jan-16 14:52 
GeneralRe: Add WeakEvent to ObservableCollection using reflection Pin
Kenneth Haugland27-Jan-16 22:13
mvaKenneth Haugland27-Jan-16 22:13 
QuestionProgrammatically Attach Debugger Pin
Kevin Marois26-Jan-16 7:49
professionalKevin Marois26-Jan-16 7:49 

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.