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. c# and query result

c# and query result

Scheduled Pinned Locked Moved C#
databasecsharp
9 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.
  • U Offline
    U Offline
    User3490
    wrote on last edited by
    #1

    When the query is work will call an insert query but when it is fail will appear a message that the record didn't founded in database

    P 1 Reply Last reply
    0
    • U User3490

      When the query is work will call an insert query but when it is fail will appear a message that the record didn't founded in database

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      And what is your question? I can't see one in there at all.

      I was brought up to respect my elders. I don't respect many people nowadays.
      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      U 1 Reply Last reply
      0
      • P Pete OHanlon

        And what is your question? I can't see one in there at all.

        I was brought up to respect my elders. I don't respect many people nowadays.
        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        U Offline
        U Offline
        User3490
        wrote on last edited by
        #3

        when the query is false how can i take the result so i can use it for doing something else with this

        P 1 Reply Last reply
        0
        • U User3490

          when the query is false how can i take the result so i can use it for doing something else with this

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          What query? How is it returning false? You haven't shown a query.

          I was brought up to respect my elders. I don't respect many people nowadays.
          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          U 1 Reply Last reply
          0
          • P Pete OHanlon

            What query? How is it returning false? You haven't shown a query.

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            U Offline
            U Offline
            User3490
            wrote on last edited by
            #5

            OleDbConnection dbConnDest; dbConnDest = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= SystemA.accdb"); string query_select = "SELECT ReferenceYear FROM [MS Access;DATABASE=" + dialog.FileName +"].Questionnaires_Table1 Where ReferenceYear = '" + dateref.Text + "';"; OleDbCommand cmd_year = new OleDbCommand(query_select, dbConnDest); dbConnDest.Open(); string rfyear = cmd_year.ExecuteScalar().ToString();

            P 1 Reply Last reply
            0
            • U User3490

              OleDbConnection dbConnDest; dbConnDest = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= SystemA.accdb"); string query_select = "SELECT ReferenceYear FROM [MS Access;DATABASE=" + dialog.FileName +"].Questionnaires_Table1 Where ReferenceYear = '" + dateref.Text + "';"; OleDbCommand cmd_year = new OleDbCommand(query_select, dbConnDest); dbConnDest.Open(); string rfyear = cmd_year.ExecuteScalar().ToString();

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              So all you're doing is testing to see if ReferenceYear exists? Why not just do SELECT Count(1)... instead, and then just evaluate the count? If it's zero, the record doesn't exist? Also, you may want to pay attention to the fact your select statement is vulnerable to a SQL Injection attack.

              I was brought up to respect my elders. I don't respect many people nowadays.
              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              K U 2 Replies Last reply
              0
              • P Pete OHanlon

                So all you're doing is testing to see if ReferenceYear exists? Why not just do SELECT Count(1)... instead, and then just evaluate the count? If it's zero, the record doesn't exist? Also, you may want to pay attention to the fact your select statement is vulnerable to a SQL Injection attack.

                I was brought up to respect my elders. I don't respect many people nowadays.
                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                K Offline
                K Offline
                KiranKumar Roy
                wrote on last edited by
                #7

                Exactly true.. :)

                KiranKumar Roy

                U 1 Reply Last reply
                0
                • P Pete OHanlon

                  So all you're doing is testing to see if ReferenceYear exists? Why not just do SELECT Count(1)... instead, and then just evaluate the count? If it's zero, the record doesn't exist? Also, you may want to pay attention to the fact your select statement is vulnerable to a SQL Injection attack.

                  I was brought up to respect my elders. I don't respect many people nowadays.
                  CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                  U Offline
                  U Offline
                  User3490
                  wrote on last edited by
                  #8

                  ok i make a class and i have there the following code: public DataTable findrefyear(string dateref) { try { //Set the access command string string query_insert = "INSERT INTO Questionnaires_Table (BranchName,Factor,Region,Branch_ID,[Current_Date],No_Employees," + "No_Cashdesk,UrbanArea,TouristArea,RuralArea,GreenLinearArea,CentralStreets,EscapeBack,Collonization," + "TimeDelay,PatrolPolice,Visibility,SafeBoxRisk,StaffAccess,KeyboardActiviation,ConnectionKSC,GSMCommunicator,SystemAlarmRisk," + "InstalledSKKT,CheckSKKT,CheckDesk,CheckEntrance,SKKTRisk,RenovatedStore,MetalCashDrawers,ExtensionCash,Limits," + "CashDrawers,CasherRisk,WarningAlert,SecurityWarningDelay,WarningRisk,BothSideDoors," + "DoorsSound,ExitRisk,EmergencyCase,RobberyCase,DescriptionForm,SeminarRobbery,EducationRisk,ReferenceYear) " + "SELECT BranchName,Factor,Region,Branch_ID,Current_Date,No_Employees," + "No_Cashdesk,UrbanArea,TouristArea,RuralArea,GreenLinearArea,CentralStreets,EscapeBack,Collonization," + "TimeDelay,PatrolPolice,Visibility,(TimeDelay+PatrolPolice+Visibility)/3,StaffAccess,KeyboardActiviation,ConnectionKSC,GSMCommunicator,(StaffAccess+KeyboardActiviation+ConnectionKSC+GSMCommunicator)/4," + "InstalledSKKT,CheckSKKT,CheckDesk,CheckEntrance,(InstalledSKKT+CheckSKKT)/2,RenovatedStore,MetalCashDrawers,ExtensionCash,Limits," + "CashDrawers,(CheckDesk+CheckEntrance+RenovatedStore+MetalCashDrawers+ExtensionCash+Limits+CashDrawers)/7," + "WarningAlert,SecurityWarningDelay,(WarningAlert+SecurityWarningDelay)/2,BothSideDoors," + "DoorsSound,(BothSideDoors+DoorsSound)/2," + "EmergencyCase,RobberyCase,DescriptionForm,SeminarRobbery,(EmergencyCase+RobberyCase+DescriptionForm+SeminarRobbery)/4,ReferenceYear " + "FROM [MS Access;DAT

                  1 Reply Last reply
                  0
                  • K KiranKumar Roy

                    Exactly true.. :)

                    KiranKumar Roy

                    U Offline
                    U Offline
                    User3490
                    wrote on last edited by
                    #9

                    ok i make a class and i have there the following code: public DataTable findrefyear(string dateref) { try { //Set the access command string string query_insert = "INSERT INTO Questionnaires_Table (BranchName,Factor,Region,Branch_ID,[Current_Date],No_Employees," + "No_Cashdesk,UrbanArea,TouristArea,RuralArea,GreenLinearArea,CentralStreets,EscapeBack,Collonization," + "TimeDelay,PatrolPolice,Visibility,SafeBoxRisk,StaffAccess,KeyboardActiviation,ConnectionKSC,GSMCommunicator,SystemAlarmRisk," + "InstalledSKKT,CheckSKKT,CheckDesk,CheckEntrance,SKKTRisk,RenovatedStore,MetalCashDrawers,ExtensionCash,Limits," + "CashDrawers,CasherRisk,WarningAlert,SecurityWarningDelay,WarningRisk,BothSideDoors," + "DoorsSound,ExitRisk,EmergencyCase,RobberyCase,DescriptionForm,SeminarRobbery,EducationRisk,ReferenceYear) " + "SELECT BranchName,Factor,Region,Branch_ID,Current_Date,No_Employees," + "No_Cashdesk,UrbanArea,TouristArea,RuralArea,GreenLinearArea,CentralStreets,EscapeBack,Collonization," + "TimeDelay,PatrolPolice,Visibility,(TimeDelay+PatrolPolice+Visibility)/3,StaffAccess,KeyboardActiviation,ConnectionKSC,GSMCommunicator,(StaffAccess+KeyboardActiviation+ConnectionKSC+GSMCommunicator)/4," + "InstalledSKKT,CheckSKKT,CheckDesk,CheckEntrance,(InstalledSKKT+CheckSKKT)/2,RenovatedStore,MetalCashDrawers,ExtensionCash,Limits," + "CashDrawers,(CheckDesk+CheckEntrance+RenovatedStore+MetalCashDrawers+ExtensionCash+Limits+CashDrawers)/7," + "WarningAlert,SecurityWarningDelay,(WarningAlert+SecurityWarningDelay)/2,BothSideDoors," + "DoorsSound,(BothSideDoors+DoorsSound)/2," + "EmergencyCase,RobberyCase,DescriptionForm,SeminarRobbery,(EmergencyCase+RobberyCase+DescriptionForm+SeminarRobbery)/4,ReferenceYear " + "FROM [MS Access;DAT

                    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