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. whats wrong?

whats wrong?

Scheduled Pinned Locked Moved C#
helpquestion
3 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.
  • A Offline
    A Offline
    ASGill
    wrote on last edited by
    #1

    private void btnAddP_Click(object sender, System.EventArgs e) { try { createSqlConnection(); if ( txtName.Text != "" && txtHPNO.Text != "") { myCommand = new SqlCommand("INSERT INTO Patient(Acct ID, Name, Age, Height, Weight, Address, IcNo, HomeNo, HpNo, EName, EPhoneNo, ERelation, Date, Status, Remarks) VALUES('"+@txtAcctId.Text+"','"+@txtName.Text+"','"+@txtAge.Text+"','"+@txtHeight.Text+"','"+@txtWeight.Text+"','"+@txtAdd.Text="','"+@txtICNO.Text+"','"+@txtHomeNo.Text+"','"+@txtHPNO.Text+"','"+@txtEName.Text+"','"+@txtEPhoneNo.Text+"','"+@txtERelation.Text+"','"+@dTimeDate.Text+"','"+@txtStatus.Text+"','"+@txtRemarks.Text+"')",myConnection); MessageBox.Show("Creating New Patient Record.....", "Information"); myCommand.ExecuteNonQuery(); MessageBox.Show("New Patient Record Created","Information"); myConnection.Close(); } else { MessageBox.Show("All Text Boxes Should be Filled with Information","Reminder"); } } catch (Exception error1) { MessageBox.Show(error1.ToString()); } when i compile the .cs file i get an error..can anyone tell me whats wrong D:\ASGill\D E G R E E\D. Final Year Project (7)\SOFTWARE\C.I.System\CLINICINFORMATIONSYSTEM\AddPatient.cs(534): The left-hand side of an assignment must be a variable, property or indexer what does it mean?... thx Arvinder Gill

    U H 2 Replies Last reply
    0
    • A ASGill

      private void btnAddP_Click(object sender, System.EventArgs e) { try { createSqlConnection(); if ( txtName.Text != "" && txtHPNO.Text != "") { myCommand = new SqlCommand("INSERT INTO Patient(Acct ID, Name, Age, Height, Weight, Address, IcNo, HomeNo, HpNo, EName, EPhoneNo, ERelation, Date, Status, Remarks) VALUES('"+@txtAcctId.Text+"','"+@txtName.Text+"','"+@txtAge.Text+"','"+@txtHeight.Text+"','"+@txtWeight.Text+"','"+@txtAdd.Text="','"+@txtICNO.Text+"','"+@txtHomeNo.Text+"','"+@txtHPNO.Text+"','"+@txtEName.Text+"','"+@txtEPhoneNo.Text+"','"+@txtERelation.Text+"','"+@dTimeDate.Text+"','"+@txtStatus.Text+"','"+@txtRemarks.Text+"')",myConnection); MessageBox.Show("Creating New Patient Record.....", "Information"); myCommand.ExecuteNonQuery(); MessageBox.Show("New Patient Record Created","Information"); myConnection.Close(); } else { MessageBox.Show("All Text Boxes Should be Filled with Information","Reminder"); } } catch (Exception error1) { MessageBox.Show(error1.ToString()); } when i compile the .cs file i get an error..can anyone tell me whats wrong D:\ASGill\D E G R E E\D. Final Year Project (7)\SOFTWARE\C.I.System\CLINICINFORMATIONSYSTEM\AddPatient.cs(534): The left-hand side of an assignment must be a variable, property or indexer what does it mean?... thx Arvinder Gill

      U Offline
      U Offline
      Uwe Keim
      wrote on last edited by
      #2

      Would be good to know what line 534 is... -- - Free Windows-based CMS: www.zeta-software.de/enu/producer/freeware/download.html - See me: www.magerquark.de - MSN Messenger: uwe_keim@hotmail.com

      1 Reply Last reply
      0
      • A ASGill

        private void btnAddP_Click(object sender, System.EventArgs e) { try { createSqlConnection(); if ( txtName.Text != "" && txtHPNO.Text != "") { myCommand = new SqlCommand("INSERT INTO Patient(Acct ID, Name, Age, Height, Weight, Address, IcNo, HomeNo, HpNo, EName, EPhoneNo, ERelation, Date, Status, Remarks) VALUES('"+@txtAcctId.Text+"','"+@txtName.Text+"','"+@txtAge.Text+"','"+@txtHeight.Text+"','"+@txtWeight.Text+"','"+@txtAdd.Text="','"+@txtICNO.Text+"','"+@txtHomeNo.Text+"','"+@txtHPNO.Text+"','"+@txtEName.Text+"','"+@txtEPhoneNo.Text+"','"+@txtERelation.Text+"','"+@dTimeDate.Text+"','"+@txtStatus.Text+"','"+@txtRemarks.Text+"')",myConnection); MessageBox.Show("Creating New Patient Record.....", "Information"); myCommand.ExecuteNonQuery(); MessageBox.Show("New Patient Record Created","Information"); myConnection.Close(); } else { MessageBox.Show("All Text Boxes Should be Filled with Information","Reminder"); } } catch (Exception error1) { MessageBox.Show(error1.ToString()); } when i compile the .cs file i get an error..can anyone tell me whats wrong D:\ASGill\D E G R E E\D. Final Year Project (7)\SOFTWARE\C.I.System\CLINICINFORMATIONSYSTEM\AddPatient.cs(534): The left-hand side of an assignment must be a variable, property or indexer what does it mean?... thx Arvinder Gill

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        Didn't I tell you before that you shouldn't use string concatenation for SQL queries? What in the hell do you think the OleDbParameter and SqlParameter are for? ADO.NET introduces parameterized expressions which take ALL of the encoding work out of your application. Got a quote in one of your variables? With your way, you have to parse your values and make sure they quotes are escaped or encoded. With parameterized queries, you don't have to worry about it. Besides, massive string concatenation like you're doing is a drastic performance decrease, resulting in (m-1)O(2n) times where m is the number of strings and n is the characters in each string. See the OleDbParameter[^] class documentation in the .NET Framework SDK for more information and an example. Most likely, not escaping or encoding your string values is what's causing that error since the string is generated and sent to the database engine AS IS. Also, don't prompt the user before executing the query! First of all, it's annoying. Second of all, if you open the connection before prompting and they don't respond for a while (why would they think they need to answer such a stupid dialog - no other program does it; they just work). The connection gets closed and your call to ExecuteNonQuery throws an exception. Also, put your _connection_.Close in the finally block to make sure it gets closed on success or failure (exception). Microsoft has recommended this time and time again if you actually read the .NET Framework SDK. The finally block will always run regardless of whether or not an exception was thrown (always except for when Environment.Exit is called, which unloads the CLR - and your application - immediately).

        Microsoft MVP, Visual C# My Articles

        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