0% found this document useful (0 votes)
23 views

DB2 Connection

C# DB2 Connection DataBase use using using using using. Using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.forms. Try system.IO.file.writealltext(path, str.ToString(), Encoding.UTF8); catch (Exception ex.Message); console.writeline("Exception

Uploaded by

jose_luis_08
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

DB2 Connection

C# DB2 Connection DataBase use using using using using. Using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.forms. Try system.IO.file.writealltext(path, str.ToString(), Encoding.UTF8); catch (Exception ex.Message); console.writeline("Exception

Uploaded by

jose_luis_08
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C# DB2 Connection DataBase

using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

using System.Data.OleDb; using System.IO; using IBM.Data.DB2; namespace Honda_Studio { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnTest_Click(object sender, EventArgs e) { string connStringLocal = "Provider=IBMDADB2;Database=QGAL1DB;HostName=THCL1DB1;Protocol=TCPIP;Port=60004;Uid=gal01 ;Pwd=gal01;"; OleDbConnection connLocal = new OleDbConnection(connStringLocal); OleDbDataAdapter da_local = new OleDbDataAdapter(@"SELECT * FROM GALADM.TEMPLATES_TBX", connStringLocal); DataTable td = new DataTable(); try { da_local.Fill(td); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); } // save to CSV ExportDatasetToCsvFile(td, @"c:\DotNet _DB2\EMPLOYEE_II.csv"); } static void ExportDatasetToCsvFile(DataTable table, string path) { StringBuilder str = new StringBuilder(); foreach (DataRow dr in table.Rows) { foreach (object field in dr.ItemArray) { str.Append(field.ToString() + ","); } str.Replace(",", Environment.NewLine, str.Length - 1, 1); }

C# DB2 Connection DataBase


try { System.IO.File.WriteAllText(path, str.ToString(), Encoding.UTF8); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); } } } }

You might also like