Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I can not understand the error.....code bellow...for trans data from sql database to another

I can not understand the error.....code bellow...for trans data from sql database to another

Scheduled Pinned Locked Moved C#
databasehelp
18 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Member 12899746

    this is debugger error(Specified cast is not valid.)

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #7

    So use the debugger to look at the value of that cell and find out what type of data it contains. When you know that, you can start looking at why it isn't a boolean value. We can't do that for you: we can't run your code, and don't have your data which fills the table if we could!

    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    M 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      So use the debugger to look at the value of that cell and find out what type of data it contains. When you know that, you can start looking at why it isn't a boolean value. We can't do that for you: we can't run your code, and don't have your data which fills the table if we could!

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      M Offline
      M Offline
      Member 12899746
      wrote on last edited by
      #8

      did you have a time to take a look via teamviewr

      OriginalGriffO 1 Reply Last reply
      0
      • M Member 12899746

        did you have a time to take a look via teamviewr

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #9

        Are you clinically insane? You would allow total strangers you never met to remotely control your PC? Have you any idea what some of them might do? Have you ever heard of ransomware? If you have that enabled, disable it immediately! Use the debugger. Look at the cell content. It should tell you a lot.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        M 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Are you clinically insane? You would allow total strangers you never met to remotely control your PC? Have you any idea what some of them might do? Have you ever heard of ransomware? If you have that enabled, disable it immediately! Use the debugger. Look at the cell content. It should tell you a lot.

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          M Offline
          M Offline
          Member 12899746
          wrote on last edited by
          #10

          no i'm not clinically insane.... but we are in a community to help each author.and i'm stacked.

          OriginalGriffO 1 Reply Last reply
          0
          • M Member 12899746

            no i'm not clinically insane.... but we are in a community to help each author.and i'm stacked.

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #11

            We are in a community to help each other, but you have no idea who people are, and what they are going to do. This is the real world, and leaving your machine open for total strangers to access and do whatever they want - and if you give them access to VS that's exactly what they can do - is not "asking for trouble" it's inviting it indoors, giving it a beer, and telling it where you keep your credit cards! :laugh: Be realistic and honest: you know how to use the debugger, don't you? (If you don't, then say so and we'll try to get you started. But not telling us relevant information is just wasting your own time, as well as ours)

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            M 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              We are in a community to help each other, but you have no idea who people are, and what they are going to do. This is the real world, and leaving your machine open for total strangers to access and do whatever they want - and if you give them access to VS that's exactly what they can do - is not "asking for trouble" it's inviting it indoors, giving it a beer, and telling it where you keep your credit cards! :laugh: Be realistic and honest: you know how to use the debugger, don't you? (If you don't, then say so and we'll try to get you started. But not telling us relevant information is just wasting your own time, as well as ours)

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              M Offline
              M Offline
              Member 12899746
              wrote on last edited by
              #12

              many thanks for your advice and your time.

              OriginalGriffO 1 Reply Last reply
              0
              • M Member 12899746

                many thanks for your advice and your time.

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #13

                You're welcome!

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                M 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  You're welcome!

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                  M Offline
                  M Offline
                  Member 12899746
                  wrote on last edited by
                  #14

                  i get my issue.... i need to get the value from DataGridView that was selected into array. can you write to me example code.

                  OriginalGriffO 1 Reply Last reply
                  0
                  • M Member 12899746

                    i get my issue.... i need to get the value from DataGridView that was selected into array. can you write to me example code.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #15

                    Sorry, but I don't understand what you said: remember I only get exactly what you type to work from. Can you explain in more detail, perhaps?

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    M 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Sorry, but I don't understand what you said: remember I only get exactly what you type to work from. Can you explain in more detail, perhaps?

                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                      M Offline
                      M Offline
                      Member 12899746
                      wrote on last edited by
                      #16

                      i need code for get selected column value from datagridview into array list //foreach (DataGridViewRow row in this.dataGridView1.Rows) //{ // if ((((bool)(row.Cells[this.invoiceNO.Index].Value)) == true)) // { // a.Add(row.Cells[this.invoiceNO.Index].Value); // } //}

                      OriginalGriffO 1 Reply Last reply
                      0
                      • M Member 12899746

                        i need code for get selected column value from datagridview into array list //foreach (DataGridViewRow row in this.dataGridView1.Rows) //{ // if ((((bool)(row.Cells[this.invoiceNO.Index].Value)) == true)) // { // a.Add(row.Cells[this.invoiceNO.Index].Value); // } //}

                        OriginalGriffO Offline
                        OriginalGriffO Offline
                        OriginalGriff
                        wrote on last edited by
                        #17

                        The problem is that you aren't thinking about what is going on here: the value you are casting to a bool is not a bool value, so the cast fails: that can't be "fixed" at that point - you need to find out what it actually is and why it isn't the value you are expecting. And the only way to do that is to use the debugger while your code is running and look at what the actual data looks like. No amount of code I could give you would fix that - because either the index is wrong, the data is wrong, the table isn't organised as you think it is, or it's totally the wrong table. We can't tell you which of those: but the debugger probably can almost instantly!

                        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                        1 Reply Last reply
                        0
                        • M Member 12899746

                          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\] + "',";
                          
                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #18

                          As long as you keep mixing "business logic" in with your "data access" logic, your life will continue to be difficult. You are simply copying and pasting each "case", without any thought to the amount of duplicate code you are creating. I would tell you to rewrite what you've got instead of helping you to "fix" it (and continuing to support your bad habits). Or are you getting paid by lines-of-code?

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups