whats wrong?
-
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 -
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 GillWould 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
-
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 GillDidn't I tell you before that you shouldn't use string concatenation for SQL queries? What in the hell do you think the
OleDbParameter
andSqlParameter
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 toExecuteNonQuery
throws an exception. Also, put your_connection_.Close
in thefinally
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. Thefinally
block will always run regardless of whether or not an exception was thrown (always except for whenEnvironment.Exit
is called, which unloads the CLR - and your application - immediately).Microsoft MVP, Visual C# My Articles