Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
PraiseRe: Expressions In C# Pin
John C Rayan30-Dec-16 3:29
professionalJohn C Rayan30-Dec-16 3:29 
SuggestionRe: Expressions In C# Pin
John C Rayan30-Dec-16 4:31
professionalJohn C Rayan30-Dec-16 4:31 
Questionpas de dèfinition dans geolocator pour RequestAccessAsync dans windows10 Pin
Member 865861426-Dec-16 23:44
Member 865861426-Dec-16 23:44 
AnswerRe: pas de dèfinition dans geolocator pour RequestAccessAsync dans windows10 Pin
OriginalGriff27-Dec-16 0:46
mveOriginalGriff27-Dec-16 0:46 
AnswerRe: pas de dèfinition dans geolocator pour RequestAccessAsync dans windows10 Pin
Patrice T27-Dec-16 22:47
mvePatrice T27-Dec-16 22:47 
QuestionEnable Mouse in c# RDP viewer Pin
Member 1289017426-Dec-16 19:53
Member 1289017426-Dec-16 19:53 
AnswerRe: Enable Mouse in c# RDP viewer Pin
Richard MacCutchan26-Dec-16 21:33
mveRichard MacCutchan26-Dec-16 21:33 
GeneralI can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 20:37
Member 1289974625-Dec-16 20:37 
C#
private void exprtbtn_Click(object sender, EventArgs e)
       {
           try
           {
               if ((this.dataGridView1.Rows.Count == 0))
               {
                   MessageBox.Show("Please select Vouchers");
               }
               else
               {
                   //  HEaders Vouchers
                   SqlConnection con = null;
                   SqlConnection con2 = null;
                   connClass cs = new connClass();
                   con = new SqlConnection(cs.distiConn1);
                   con2 = new SqlConnection(cs.sourceConn2);

                   ArrayList a = new ArrayList();
                   DataTable DT = new DataTable();
                   SqlCommand cmd = new SqlCommand();
                   SqlTransaction trans = default(SqlTransaction);

                   con.Open();
                   trans = con.BeginTransaction();
                   cmd.Connection = con;
                   cmd.Transaction = trans;

                   SqlCommand cmdLive = new SqlCommand();
                   cmdLive.Connection = con2;
                   SqlDataAdapter DR = default(SqlDataAdapter);

                   //foreach (DataGridViewRow row in dataGridView1.Rows)
                   //{
                   //    if ((bool) row.Cells[this.invoiceNO.Index].Value == true)

                   //    {
                   //        a.Add(row.Cells[this.invoiceNO.Index].Value);
                   //    }
                   //}
                   //foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   //{
                   //    if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                   //    {
                   //        a.Add(row.Cells[this.invoiceNO.Index].Value);

                   //    }
                   //} error in the anderline code
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((((bool)(row.Cells[this.invoiceNO.Index].Value)) == true))
                       {
                           a.Add(row.Cells[this.invoiceNO.Index].Value);
                       }

                   }
                   int C = a.Count;
                   string str = "(";
                   int i = 0;
                   while (i < C - 1)
                   {
                       str += "'" + a[i] + "',";
                       i = i + 1;
                   }
                   str += "'" + a[C - 1] + "')";
                   //int C = a.Count;
                   //string str = "(";
                   //int i = 0;
                   //while ((i
                   //    < (C - 1)))
                   //{
                   //    str = (str + ("\'"
                   //        + (a[i] + "\',")));
                   //    i = (i + 1);

                   //}
                   //str = (str + ("\'"
                   //    + (a[(C - 1)] + "\')")));
                   cmdLive.CommandText = ("Select * from InvDailyHF where compno=1   and VouYear="
                                              + (this.yercombox.Text + (" and VouType="
                                              + (this.vochcombox.Text + (" and VouNo in " + str)))));
                   DR = new SqlDataAdapter(cmdLive);
                   DR.Fill(DT);

                   int CC = DT.Columns.Count;
                   string strn = "(";
                   int i1 = 0;
                   foreach (DataRow R in DT.Rows)
                   {
                       while (i1 < CC - 1)
                       {
                           strn += "'" + R[i1] + "',";
                           i1 = i1 + 1;
                       }
                       strn += "'" + R[CC - 1] + "')";

                       //int CC = DT.Columns.Count;
                       //string strn = "(";
                       //int i1 = 0;
                       //foreach (DataRow R in DT.Rows)
                       //{
                       //    while ((i1
                       //        < (CC - 1)))
                       //    {
                       //        strn = (strn + ("\'"
                       //          + (R[i1] + "\',")));
                       //        i1 = (i1 + 1);
                       //    }
                       //    strn = (strn + ("\'"
                       //        + (R[(CC - 1)] + "\')")));
                       cmd.CommandText = ("Insert InvDailyHF values" + strn);
                       cmd.ExecuteNonQuery();
                   }
               }

               SqlConnection con3 = null;
               SqlConnection con4 = null;
               connClass csu = new connClass();
               con3 = new SqlConnection(csu.sourceConn2);
               con4 = new SqlConnection(csu.distiConn2);

               ArrayList aH = new ArrayList();
               DataTable DTH = new DataTable();
               SqlCommand cmd1 = new SqlCommand();
               SqlCommand cmdLiveh = new SqlCommand();

               cmdLiveh.Connection = con3;
               cmd1.Connection = con4;
               SqlDataAdapter DAH = default(SqlDataAdapter);

               foreach (DataGridViewRow row in this.dataGridView1.Rows)
               {
                   if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                   {
                       aH.Add(row.Cells[this.invoiceNO.Index].Value);
                   }
               }
               int BB = aH.Count;
               string strn1 = "(";
               int i2 = 0;
               while (i2 < BB - 1)
               {
                   strn1 += "'" + aH[i2] + "',";
                   i2 = i2 + 1;
               }
               strn1 += "'" + aH[BB - 1] + "')";
               //int BB = aH.Count;
               //string strn1 = "(";
               //int i2 = 0;
               //while ((i2
               //    < (BB - 1)))
               //{
               //    strn1 = (strn1 + ("\'"
               //        + (aH[i2] + "\',")));
               //    i2 = i2 + 1;
               //}
               //strn1 = (strn1 + ("\'"
               //              + (aH[(BB - 1)] + "\')")));
               cmdLiveh.CommandText = ("Select * from InvDailyDF where compno=1   and VouYear="
                                        + (this.yercombox.Text + (" and VouType="
                                        + (this.vochcombox.Text + (" and VouNo in " + strn1)))));
               DAH = new SqlDataAdapter(cmdLiveh);
               DAH.Fill(DTH);

               int BB1 = DTH.Columns.Count;
               string strn2 = "(";
               int i3 = 0;
               foreach (DataRow R in DTH.Rows)
               {
                   while (i3 < BB1 - 1)
                   {
                       strn2 += "'" + R[i3] + "',";
                       i3 = i3 + 1;
                   }
                   strn2 += "'" + R[BB1 - 1] + "')";
               }
               //int BB1 = DTH.Columns.Count;
               //string strn2 = "(";
               //int i3 = 0;
               //foreach (DataRow R in DTH.Rows)
               //{
               //    while ((i3
               //        < (BB1 - 1)))
               //    {
               //        strn2 = (strn2 + ("\'"
               //            + (R[i3] + "\',")));
               //        i3 = (i3 + 1);
               //    }
               //    strn2 = (strn2 + ("\'"
               //        + (R[(BB1 - 1)] + "\')")));
               cmd1.CommandText = ("Insert InvDailyDF values" + strn2);
               cmd1.ExecuteNonQuery();
               strn2 = "(";
               i3 = 0;



               // Transactions Transfer(DocType 4)

               //SqlConnection con4 = new SqlConnection
               ArrayList transData = new ArrayList();
               DataTable transDT = new DataTable();
               SqlCommand cmdTrans = new SqlCommand();
               SqlDataAdapter transDR = new SqlDataAdapter();

               int transCount;
               int transCounter;
               int DTcounter;
               int iString;
               string transDA = "(";

               if (vochcombox.Text == "9")
               {
                   cmdTrans.Connection = new SqlConnection(cs.sourceConn2);
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                       {
                           transData.Add(row.Cells[this.invoiceNO.Index].Value);
                       }
                   }
                   transCount = transData.Count;
                   transDA = "(";
                   transCounter = 0;
                   while ((transCounter
                             < (transCount - 1)))
                   {
                       transDA = (transDA + ("\'"
                           + (transData[transCounter] + ("\',"))));
                       transCounter = (transCounter + 1);
                   }
                   transDA = (transDA + ("\'"
                                     + (transData[(transCount - 1)] + "\')")));
                   cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1   and vod_year="
                                              + (this.yercombox.Text + (" and vod_type=4 and  vod_num in " + transDA)));
                   transDR = new SqlDataAdapter(cmdTrans);
                   transDR.Fill(transDT);
                   DTcounter = transDT.Columns.Count;
                   transDA = "(";
                   iString = 0;
                   foreach (DataRow R in transDT.Rows)
                   {
                       while (iString
                           < (DTcounter - 1))
                       {
                           transDA = transDA + ("\'"
                               + (R[iString] + "\',)"));
                           iString = (iString + 1);
                       }
                       transDA = (transDA + ("\'"
                           + (R[(DTcounter - 1)] + "\')")));
                       cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
                       cmdTrans.ExecuteNonQuery();
                       transDA = "(";
                       iString = 0;
                   }
               }
               else if (this.vochcombox.Text == "2")
               {
                   cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                       {
                           transData.Add(row.Cells[this.invoiceNO.Index].Value);
                       }
                   }
                   transCount = transData.Count;
                   transDA = "(";
                   transCounter = 0;
                   while ((transCounter
                             < (transCount - 1)))
                   {
                       transDA = (transDA + ("\'"
                           + (transData[transCounter] + ("\',"))));
                       transCounter = (transCounter + 1);
                   }
                   transDA = (transDA + ("\'"
                                     + (transData[(transCount - 1)] + "\')")));
                   cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1   and vod_year="
                                              + (this.yercombox.Text + (" and vod_type=6 and  vod_num in " + transDA)));
                   transDR = new SqlDataAdapter(cmdTrans);
                   transDR.Fill(transDT);
                   DTcounter = transDT.Columns.Count;
                   transDA = "(";
                   iString = 0;
                   foreach (DataRow R in transDT.Rows)
                   {
                       while (iString
                           < (DTcounter - 1))
                       {
                           transDA = transDA + ("\'"
                               + (R[iString] + "\',)"));
                           iString = (iString + 1);
                       }
                       transDA = (transDA + ("\'"
                           + (R[(DTcounter - 1)] + "\')")));
                       cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
                       cmdTrans.ExecuteNonQuery();
                       transDA = "(";
                       iString = 0;
                   }
               }
               else if (this.vochcombox.Text == "3")
               {
                   cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                       {
                           transData.Add(row.Cells[this.invoiceNO.Index].Value);
                       }
                   }
                   transCount = transData.Count;
                   transDA = "(";
                   transCounter = 0;
                   while ((transCounter
                             < (transCount - 1)))
                   {
                       transDA = (transDA + ("\'"
                           + (transData[transCounter] + ("\',"))));
                       transCounter = (transCounter + 1);
                   }
                   transDA = (transDA + ("\'"
                                     + (transData[(transCount - 1)] + "\')")));
                   cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1   and vod_year="
                                              + (this.yercombox.Text + (" and vod_type=8 and  vod_num in " + transDA)));
                   transDR = new SqlDataAdapter(cmdTrans);
                   transDR.Fill(transDT);
                   DTcounter = transDT.Columns.Count;
                   transDA = "(";
                   iString = 0;
                   foreach (DataRow R in transDT.Rows)
                   {
                       while (iString
                           < (DTcounter - 1))
                       {
                           transDA = transDA + ("\'"
                               + (R[iString] + "\',)"));
                           iString = (iString + 1);
                       }
                       transDA = (transDA + ("\'"
                           + (R[(DTcounter - 1)] + "\')")));
                       cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
                       cmdTrans.ExecuteNonQuery();
                       transDA = "(";
                       iString = 0;
                   }
               }

               else if (this.vochcombox.Text == "10")
               {
                   cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                       {
                           transData.Add(row.Cells[this.invoiceNO.Index].Value);
                       }
                   }
                   transCount = transData.Count;
                   transDA = "(";
                   transCounter = 0;
                   while ((transCounter
                             < (transCount - 1)))
                   {
                       transDA = (transDA + ("\'"
                           + (transData[transCounter] + ("\',"))));
                       transCounter = (transCounter + 1);
                   }
                   transDA = (transDA + ("\'"
                                     + (transData[(transCount - 1)] + "\')")));
                   cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1   and vod_year="
                                              + (this.yercombox.Text + (" and vod_type=9 and  vod_num in " + transDA)));
                   transDR = new SqlDataAdapter(cmdTrans);
                   transDR.Fill(transDT);
                   DTcounter = transDT.Columns.Count;
                   transDA = "(";
                   iString = 0;
                   foreach (DataRow R in transDT.Rows)
                   {
                       while (iString
                           < (DTcounter - 1))
                       {
                           transDA = transDA + ("\'"
                               + (R[iString] + "\',)"));
                           iString = (iString + 1);
                       }
                       transDA = (transDA + ("\'"
                           + (R[(DTcounter - 1)] + "\')")));
                       cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
                       cmdTrans.ExecuteNonQuery();
                       transDA = "(";
                       iString = 0;
                   }

               }
               else if (this.vochcombox.Text == "4")
               {
                   cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                       {
                           transData.Add(row.Cells[this.invoiceNO.Index].Value);
                       }
                   }
                   transCount = transData.Count;
                   transDA = "(";
                   transCounter = 0;
                   while ((transCounter
                             < (transCount - 1)))
                   {
                       transDA = (transDA + ("\'"
                           + (transData[transCounter] + ("\',"))));
                       transCounter = (transCounter + 1);
                   }
                   transDA = (transDA + ("\'"
                                     + (transData[(transCount - 1)] + "\')")));
                   cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1   and vod_year="
                                              + (this.yercombox.Text + (" and vod_type=13 and  vod_num in " + transDA)));
                   transDR = new SqlDataAdapter(cmdTrans);
                   transDR.Fill(transDT);
                   DTcounter = transDT.Columns.Count;
                   transDA = "(";
                   iString = 0;
                   foreach (DataRow R in transDT.Rows)
                   {
                       while (iString
                           < (DTcounter - 1))
                       {
                           transDA = transDA + ("\'"
                               + (R[iString] + "\',)"));
                           iString = (iString + 1);
                       }
                       transDA = (transDA + ("\'"
                           + (R[(DTcounter - 1)] + "\')")));
                       cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
                       cmdTrans.ExecuteNonQuery();
                       transDA = "(";
                       iString = 0;
                   }
               }
               else if (this.vochcombox.Text == "13")
               {
                   cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                       {
                           transData.Add(row.Cells[this.invoiceNO.Index].Value);
                       }
                   }
                   transCount = transData.Count;
                   transDA = "(";
                   transCounter = 0;
                   while ((transCounter
                             < (transCount - 1)))
                   {
                       transDA = (transDA + ("\'"
                           + (transData[transCounter] + ("\',"))));
                       transCounter = (transCounter + 1);
                   }
                   transDA = (transDA + ("\'"
                                     + (transData[(transCount - 1)] + "\')")));
                   cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1   and     vod_year="
                                              + (this.yercombox.Text + (" and vod_type=14 and  vod_num in " + transDA)));
                   transDR = new SqlDataAdapter(cmdTrans);
                   transDR.Fill(transDT);
                   DTcounter = transDT.Columns.Count;
                   transDA = "(";
                   iString = 0;

                   foreach (DataRow R in transDT.Rows)
                   {
                       while (iString
                           < (DTcounter - 1))
                       {
                           transDA = transDA + ("\'"
                               + (R[iString] + "\',)"));
                           iString = (iString + 1);
                       }
                       transDA = (transDA + ("\'"
                           + (R[(DTcounter - 1)] + "\')")));
                       cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
                       cmdTrans.ExecuteNonQuery();
                       transDA = "(";
                       iString = 0;
                   }
               }
               else if (this.vochcombox.Text == "6")
               {
                   cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
                   foreach (DataGridViewRow row in this.dataGridView1.Rows)
                   {
                       if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
                       {
                           transData.Add(row.Cells[this.invoiceNO.Index].Value);
                       }
                   }
                   transCount = transData.Count;
                   transDA = "(";
                   transCounter = 0;
                   while ((transCounter
                             < (transCount - 1)))
                   {
                       transDA = (transDA + ("\'"
                           + (transData[transCounter] + ("\',"))));
                       transCounter = (transCounter + 1);
                   }
                   transDA = (transDA + ("\'"
                                     + (transData[(transCount - 1)] + "\')")));
                   cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1   and vod_year="
                                              + (this.yercombox.Text + (" and vod_type=61 and  vod_num in " + transDA)));
                   transDR = new SqlDataAdapter(cmdTrans);
                   transDR.Fill(transDT);
                   DTcounter = transDT.Columns.Count;
                   transDA = "(";
                   iString = 0;
                   foreach (DataRow R in transDT.Rows)
                   {
                       while (iString
                           < (DTcounter - 1))
                       {
                           transDA = transDA + ("\'"
                               + (R[iString] + "\',)"));
                           iString = (iString + 1);
                       }
                       transDA = (transDA + ("\'"
                           + (R[(DTcounter - 1)] + "\')")));
                       cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
                       cmdTrans.ExecuteNonQuery();
                       transDA = "(";
                       iString = 0;
                   }
               }
           }

           catch (Exception ex)
           {
               MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

           }

       }


modified 26-Dec-16 2:59am.

QuestionRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Richard MacCutchan25-Dec-16 20:39
mveRichard MacCutchan25-Dec-16 20:39 
AnswerRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:05
Member 1289974625-Dec-16 21:05 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Richard MacCutchan25-Dec-16 21:13
mveRichard MacCutchan25-Dec-16 21:13 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 20:54
mveOriginalGriff25-Dec-16 20:54 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:07
Member 1289974625-Dec-16 21:07 
AnswerRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 21:19
mveOriginalGriff25-Dec-16 21:19 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:21
Member 1289974625-Dec-16 21:21 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 21:33
mveOriginalGriff25-Dec-16 21:33 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:37
Member 1289974625-Dec-16 21:37 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 21:49
mveOriginalGriff25-Dec-16 21:49 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 21:59
Member 1289974625-Dec-16 21:59 
GeneralRe: I'm get confusing and A state of mental distractions I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 22:00
mveOriginalGriff25-Dec-16 22:00 
GeneralRe:I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 22:46
Member 1289974625-Dec-16 22:46 
GeneralRe:I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 23:00
mveOriginalGriff25-Dec-16 23:00 
GeneralRe:I can not understand the error.....code bellow...for trans data from sql database to another Pin
Member 1289974625-Dec-16 23:24
Member 1289974625-Dec-16 23:24 
GeneralRe:I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 23:41
mveOriginalGriff25-Dec-16 23:41 
GeneralRe: I can not understand the error.....code bellow...for trans data from sql database to another Pin
Gerry Schmitz26-Dec-16 6:01
mveGerry Schmitz26-Dec-16 6:01 

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.