예제 #1
0
        public TdDataAdapter GetAttachments(int Defectid)
        {
            //Define the Command Object
            int    ID      = 0;
            string defect1 = "";
            //IDDefect = Convert.ToInt32(DefectID);
            TdConnection con = new TdConnection(strConnString);

            Teradata.Client.Provider.TdDataAdapter AdvancedDefectSearch =
                new Teradata.Client.Provider.TdDataAdapter("Select Path from  coebatch.tbl_Attachments where  DefectID = " + Defectid + ";", con);

            try
            {
                //Open the Connection  to connect to the database
                con.Open();
                return(AdvancedDefectSearch);

                //Execute the Query
                //AdvancedDefectSearch.ExecuteNonQuery();
                //TdDataReader r = AdvancedDefectSearch.ExecuteReader();
                //if (r.Read())
                //{
                //    defect1 = r["DefectID"].ToString();


                //}
                //r.Close();

                //if (defect1 == "")
                //{
                //    con.Close();
                //    return ID;
                //}
                //else
                //{
                //    ID = 1;
                //}


                // nextDefectId = (int)cmdNewDefect.ExecuteScalar();
            }
            catch (TdException ex)
            {
                // return ID;
            }
            finally
            {
                //Close the Connection from the Database
                con.Close();
            }
            return(AdvancedDefectSearch);
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Teradata.Client.Provider.TdConnection mainConn      = new Teradata.Client.Provider.TdConnection();
            TdConnectionStringBuilder             stringBuilder = new TdConnectionStringBuilder();

            stringBuilder.CommandTimeout    = 300;
            stringBuilder.ConnectionTimeout = 100;
            stringBuilder.DataSource        = host;
            stringBuilder.UserId            = uid;
            stringBuilder.Password          = pwd;
            mainConn.ConnectionString       = stringBuilder.ConnectionString;
            this.Text = host;
            mainConn.Open();


            StreamReader gperead = new StreamReader(@txtFile.Text);
            string       szLine  = "";

            string[] szFields;
            string[] szHeader;
            szLine   = gperead.ReadLine();
            szLine   = szLine.Replace("\"", "");
            szHeader = szLine.Split(SEPARATOR);
            Teradata.Client.Provider.TdCommand gpeCmd = new Teradata.Client.Provider.TdCommand("SELECT * FROM " + cboDatabaseList.Text + "." + cboTables.Text, mainConn);
            gpeCmd.CommandTimeout = 10000;

            int counter = 0;

            Teradata.Client.Provider.TdDataAdapter gpeAdapter = new Teradata.Client.Provider.TdDataAdapter(gpeCmd);
            gpeAdapter.UpdateBatchSize = 100000;

            gpeAdapter.KeepCommandBatchSequence = false;
            Teradata.Client.Provider.TdCommandBuilder cb = new Teradata.Client.Provider.TdCommandBuilder(gpeAdapter);
            DataTable dt = new DataTable();

            gpeAdapter.Fill(dt);

            while ((szLine = gperead.ReadLine()) != null)
            {
                szLine   = szLine.Replace("\"", "");
                szFields = szLine.Split(SEPARATOR);

                DataRow dr = dt.NewRow();

                if (szFields.GetUpperBound(0) == szHeader.GetUpperBound(0))
                {
                    for (int i = 0; i < szHeader.GetLength(0); i++)
                    {
                        if (szFields[i] == "?")
                        {
                            dr[szHeader[i]] = DBNull.Value;
                        }
                        else if (dr.Table.Columns[szHeader[i]].DataType == typeof(DateTime))
                        {
                            try {
                                dr[szHeader[i]] = Convert.ToDateTime(szFields[i].Trim('\"'));
                            }
                            catch (Exception ex) {
                                dr[szHeader[i]] = DBNull.Value;
                            }
                        }
                        else if (dr.Table.Columns[szHeader[i]].DataType == typeof(double))
                        {
                            dr[szHeader[i]] = Convert.ToDecimal(szFields[i].Trim('\"').Replace('.', ','));
                        }
                        else
                        {
                            try {
                                dr[szHeader[i]] = szFields[i].Trim('\"');
                            }
                            catch (Exception ex) {
                                dr[szHeader[i]] = DBNull.Value;
                            }
                        }
                    }

                    dt.Rows.Add(dr);
                }



                if ((counter++ % 100000) == 0)
                {
                    try {
                        gpeAdapter.Update(dt);
                    }
                    catch (Exception ex) {
                        MessageBox.Show(this, ex.Message);
                    }

                    textBox1.Text = (counter - 1).ToString();
                }

                Application.DoEvents();
            }

            gpeAdapter.Update(dt);
            textBox1.Text = counter.ToString();

            dt.Dispose();
            gpeCmd.Dispose();
            mainConn.Close();
            mainConn.Dispose();
            gperead.Close();
            sw.Stop();
            MessageBox.Show("Done!\n" + sw.Elapsed);
        }