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. Database & SysAdmin
  3. Database
  4. Question on VC++ and SQL

Question on VC++ and SQL

Scheduled Pinned Locked Moved Database
questionc++databasehelp
11 Posts 4 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.
  • E Offline
    E Offline
    ensger
    wrote on last edited by
    #1

    I have to make questions like this: CString abfrage; abfrage = "SELECT kstnr, kststamm.Bezeichnung, karnr, KarBezeichnung, buchungen.ktrnr, KtrBezeichnung, betrag, datum, datenart, belsymbol,\ belnr, text FROM buchungen LEFT OUTER JOIN karstamm ON buchungen.karnr = karstamm.Nummer "; abfrage = abfrage + "LEFT OUTER JOIN kststamm ON buchungen.kstnr = kststamm.Nummer "; abfrage = abfrage + " LEFT OUTER JOIN ktrstamm ON buchungen.ktrnr = ktrstamm.KtrNr WHERE datum >= "; abfrage = abfrage + "'" + kstvon.c_str() + "' AND datum <= '" + kstbis.c_str() + "'"; if (kstnr != "") abfrage = abfrage + " AND kstnr = '" + kstnr.c_str() + "'"; if (koarnr != "") abfrage = abfrage + " AND karnr = '" + koarnr.c_str() + "'"; if (datenart != "") abfrage = abfrage + " AND datenart = '" + datenart.c_str() + "'"; rs->Close(); rs->Open(CRecordset::snapshot, abfrage); Is there an easier way to make a Select in VC++?? I made this question in the Longe, unforounatly - and my question was even deleted (what's right, wrong click;)) But can anyone help here??? Thanks, Gerhard

    H J 2 Replies Last reply
    0
    • E ensger

      I have to make questions like this: CString abfrage; abfrage = "SELECT kstnr, kststamm.Bezeichnung, karnr, KarBezeichnung, buchungen.ktrnr, KtrBezeichnung, betrag, datum, datenart, belsymbol,\ belnr, text FROM buchungen LEFT OUTER JOIN karstamm ON buchungen.karnr = karstamm.Nummer "; abfrage = abfrage + "LEFT OUTER JOIN kststamm ON buchungen.kstnr = kststamm.Nummer "; abfrage = abfrage + " LEFT OUTER JOIN ktrstamm ON buchungen.ktrnr = ktrstamm.KtrNr WHERE datum >= "; abfrage = abfrage + "'" + kstvon.c_str() + "' AND datum <= '" + kstbis.c_str() + "'"; if (kstnr != "") abfrage = abfrage + " AND kstnr = '" + kstnr.c_str() + "'"; if (koarnr != "") abfrage = abfrage + " AND karnr = '" + koarnr.c_str() + "'"; if (datenart != "") abfrage = abfrage + " AND datenart = '" + datenart.c_str() + "'"; rs->Close(); rs->Open(CRecordset::snapshot, abfrage); Is there an easier way to make a Select in VC++?? I made this question in the Longe, unforounatly - and my question was even deleted (what's right, wrong click;)) But can anyone help here??? Thanks, Gerhard

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Your question is not 100% on this forum again;) anyway I forgot sql server but I think its possible can you create a view on your database and use of it on the VC++?and also you can use of CString::Insert instead abfrage = abfrage + ...;)


      WhiteSky


      E 1 Reply Last reply
      0
      • E ensger

        I have to make questions like this: CString abfrage; abfrage = "SELECT kstnr, kststamm.Bezeichnung, karnr, KarBezeichnung, buchungen.ktrnr, KtrBezeichnung, betrag, datum, datenart, belsymbol,\ belnr, text FROM buchungen LEFT OUTER JOIN karstamm ON buchungen.karnr = karstamm.Nummer "; abfrage = abfrage + "LEFT OUTER JOIN kststamm ON buchungen.kstnr = kststamm.Nummer "; abfrage = abfrage + " LEFT OUTER JOIN ktrstamm ON buchungen.ktrnr = ktrstamm.KtrNr WHERE datum >= "; abfrage = abfrage + "'" + kstvon.c_str() + "' AND datum <= '" + kstbis.c_str() + "'"; if (kstnr != "") abfrage = abfrage + " AND kstnr = '" + kstnr.c_str() + "'"; if (koarnr != "") abfrage = abfrage + " AND karnr = '" + koarnr.c_str() + "'"; if (datenart != "") abfrage = abfrage + " AND datenart = '" + datenart.c_str() + "'"; rs->Close(); rs->Open(CRecordset::snapshot, abfrage); Is there an easier way to make a Select in VC++?? I made this question in the Longe, unforounatly - and my question was even deleted (what's right, wrong click;)) But can anyone help here??? Thanks, Gerhard

        J Offline
        J Offline
        John M Drescher
        wrote on last edited by
        #3

        Try the CString::Format member. Here is what with ADO and MFC:

        CString tempStr;

        try {
        tempStr.Format("SELECT * "
        "FROM CAD_Info "
        "WHERE ( ([SessionNumber] = %d) "
        "AND ([SiteID] = %d) "
        "AND ([SeqNumber] = %d) )",
        nSession,nSiteID,nSeqNum);

          CMainDataBase::TESTHR(pRst.CreateInstance(\_\_uuidof(Recordset)));
        		
          CADORecordSetEx rst(m\_pDB,pRst);
          rst.Open(tempStr,m\_cursorType,m\_lockType, adCmdText); 
        
         // Do something with the recordset...
        

        }
        catch(CException* e)
        {
        // Do something with the error
        }
        catch (...)
        {

        }

        I know you are using CRecordSet and DAO but the syntax should be similar.

        John

        E 1 Reply Last reply
        0
        • J John M Drescher

          Try the CString::Format member. Here is what with ADO and MFC:

          CString tempStr;

          try {
          tempStr.Format("SELECT * "
          "FROM CAD_Info "
          "WHERE ( ([SessionNumber] = %d) "
          "AND ([SiteID] = %d) "
          "AND ([SeqNumber] = %d) )",
          nSession,nSiteID,nSeqNum);

            CMainDataBase::TESTHR(pRst.CreateInstance(\_\_uuidof(Recordset)));
          		
            CADORecordSetEx rst(m\_pDB,pRst);
            rst.Open(tempStr,m\_cursorType,m\_lockType, adCmdText); 
          
           // Do something with the recordset...
          

          }
          catch(CException* e)
          {
          // Do something with the error
          }
          catch (...)
          {

          }

          I know you are using CRecordSet and DAO but the syntax should be similar.

          John

          E Offline
          E Offline
          ensger
          wrote on last edited by
          #4

          Thanks for the answer, Unfortunatly I have no experience with ADO, but I have some books to learn it. Maybe I have to do so now;) BTW, the statemant above ment, this is not the rigth forum too. What would be the right one. In the Lounge (:-O sorry again), you said, I should try in the MFC-forum, but I can't find. Thanks, Gerhard

          S J 2 Replies Last reply
          0
          • H Hamid Taebi

            Your question is not 100% on this forum again;) anyway I forgot sql server but I think its possible can you create a view on your database and use of it on the VC++?and also you can use of CString::Insert instead abfrage = abfrage + ...;)


            WhiteSky


            E Offline
            E Offline
            ensger
            wrote on last edited by
            #5

            Tahnks, Seems to be a good idea. Can you tell me, what would be the right forum for a question like this. Lounge was a fault, of course:-O - sorry. Gerhard

            H 1 Reply Last reply
            0
            • E ensger

              Tahnks, Seems to be a good idea. Can you tell me, what would be the right forum for a question like this. Lounge was a fault, of course:-O - sorry. Gerhard

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Your're welcome Well Lounge was 100% fault.No programming questions please (on the Lounge);) Why you cant find MFC forum (Visual C++ / MFC) Visual C++ / MFC[^]


              WhiteSky


              E 1 Reply Last reply
              0
              • E ensger

                Thanks for the answer, Unfortunatly I have no experience with ADO, but I have some books to learn it. Maybe I have to do so now;) BTW, the statemant above ment, this is not the rigth forum too. What would be the right one. In the Lounge (:-O sorry again), you said, I should try in the MFC-forum, but I can't find. Thanks, Gerhard

                S Offline
                S Offline
                S Douglas
                wrote on last edited by
                #7

                ensger wrote:

                this is not the rigth forum too. What would be the right one.

                1: Querying the database in the manor you are, your exposing the database to SQL injection attacks. See this article for help distinguishing these attacks. SQL Injection Attacks[^] 2: Looks like you where suggested to ask this question in the MFC forum was because it’s all string manipulation. Which falls under the purview of MFC CString, although for the purposes here it’s really fine in either forum.

                ensger wrote:

                I should try in the MFC-forum, but I can't find.

                Visual C++ / MFC[^] Good Luck


                I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                E 1 Reply Last reply
                0
                • H Hamid Taebi

                  Your're welcome Well Lounge was 100% fault.No programming questions please (on the Lounge);) Why you cant find MFC forum (Visual C++ / MFC) Visual C++ / MFC[^]


                  WhiteSky


                  E Offline
                  E Offline
                  ensger
                  wrote on last edited by
                  #8

                  Becouse I opened the menue-point 'Message Boards' and searched there. And there it's called Visual C++ only. But I already found, thanks

                  H 1 Reply Last reply
                  0
                  • S S Douglas

                    ensger wrote:

                    this is not the rigth forum too. What would be the right one.

                    1: Querying the database in the manor you are, your exposing the database to SQL injection attacks. See this article for help distinguishing these attacks. SQL Injection Attacks[^] 2: Looks like you where suggested to ask this question in the MFC forum was because it’s all string manipulation. Which falls under the purview of MFC CString, although for the purposes here it’s really fine in either forum.

                    ensger wrote:

                    I should try in the MFC-forum, but I can't find.

                    Visual C++ / MFC[^] Good Luck


                    I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                    E Offline
                    E Offline
                    ensger
                    wrote on last edited by
                    #9

                    Seems to be a very interesting article. Thaks, Gerhard

                    1 Reply Last reply
                    0
                    • E ensger

                      Becouse I opened the menue-point 'Message Boards' and searched there. And there it's called Visual C++ only. But I already found, thanks

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #10

                      Not problem maybe you are new here(codeproject),but I am ready to help people ;)


                      WhiteSky


                      1 Reply Last reply
                      0
                      • E ensger

                        Thanks for the answer, Unfortunatly I have no experience with ADO, but I have some books to learn it. Maybe I have to do so now;) BTW, the statemant above ment, this is not the rigth forum too. What would be the right one. In the Lounge (:-O sorry again), you said, I should try in the MFC-forum, but I can't find. Thanks, Gerhard

                        J Offline
                        J Offline
                        John M Drescher
                        wrote on last edited by
                        #11

                        ensger wrote:

                        nfortunatly I have no experience with ADO, but I have some books to learn it.

                        I recommend ADO if you plan on writing SQL code for connecting to a MS SQL server (or the free version of that) as it is much better at that task and it works well with multithreading which with DAO you have to be very careful. Although I do not use this code I recommend this class for connecting to ADO databases: http://www.codeproject.com/database/caaadoclass1.asp[^]

                        John

                        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