i need to add a mailto string into an access db but get this error
-
"Syntax error (missing operator) in query expression ''pop1@tes.co.uk''." i use this method to build string private string buildMailToString(string email) { //phil string newMail = ""; if(email.Length >0) { newMail = @"[" + email.Trim() + "](mailto:" + email.Trim() + ")"; } return newMail; } and this for the insert private void btnAdd_Click(object sender, System.EventArgs e) { string email1 = buildMailToString(txtEmail1.Text.Trim()); string email2 = buildMailToString(txtEmail2.Text.Trim()); string email3 = buildMailToString(txtEmail3.Text.Trim()); if((this.txtCustomerID.Text == "0") || (this.txtCustomerID.Text == "")) { string sql = "INSERT INTO Customers(Title,Initials,Firstname,Lastname,HomeNumber," + "WorkNumber,Mobile,Fax,Email1,Email2,Email3,Notes) Values('" + this.txtTitle.Text + "','" + this.txtInitials.Text + "','" + this.txtFirstname.Text + "','" + this.txtLastname.Text + "','" + this.txtHomeNumber.Text + "','" + this.txtMobile.Text + "','" + this.txtWorkNumber.Text + "','" + this.txtFax.Text + "','" + email1 + "','" + email2 + "','" + email3 + "','" + this.txtNotes.Text + "')"; OleDbCommand cmd = new OleDbCommand(sql,cnn); try { cnn.Open(); cmd.ExecuteNonQuery(); how do i build the string correctly?????
-
"Syntax error (missing operator) in query expression ''pop1@tes.co.uk''." i use this method to build string private string buildMailToString(string email) { //phil string newMail = ""; if(email.Length >0) { newMail = @"[" + email.Trim() + "](mailto:" + email.Trim() + ")"; } return newMail; } and this for the insert private void btnAdd_Click(object sender, System.EventArgs e) { string email1 = buildMailToString(txtEmail1.Text.Trim()); string email2 = buildMailToString(txtEmail2.Text.Trim()); string email3 = buildMailToString(txtEmail3.Text.Trim()); if((this.txtCustomerID.Text == "0") || (this.txtCustomerID.Text == "")) { string sql = "INSERT INTO Customers(Title,Initials,Firstname,Lastname,HomeNumber," + "WorkNumber,Mobile,Fax,Email1,Email2,Email3,Notes) Values('" + this.txtTitle.Text + "','" + this.txtInitials.Text + "','" + this.txtFirstname.Text + "','" + this.txtLastname.Text + "','" + this.txtHomeNumber.Text + "','" + this.txtMobile.Text + "','" + this.txtWorkNumber.Text + "','" + this.txtFax.Text + "','" + email1 + "','" + email2 + "','" + email3 + "','" + this.txtNotes.Text + "')"; OleDbCommand cmd = new OleDbCommand(sql,cnn); try { cnn.Open(); cmd.ExecuteNonQuery(); how do i build the string correctly?????
-
"Syntax error (missing operator) in query expression ''pop1@tes.co.uk''." i use this method to build string private string buildMailToString(string email) { //phil string newMail = ""; if(email.Length >0) { newMail = @"[" + email.Trim() + "](mailto:" + email.Trim() + ")"; } return newMail; } and this for the insert private void btnAdd_Click(object sender, System.EventArgs e) { string email1 = buildMailToString(txtEmail1.Text.Trim()); string email2 = buildMailToString(txtEmail2.Text.Trim()); string email3 = buildMailToString(txtEmail3.Text.Trim()); if((this.txtCustomerID.Text == "0") || (this.txtCustomerID.Text == "")) { string sql = "INSERT INTO Customers(Title,Initials,Firstname,Lastname,HomeNumber," + "WorkNumber,Mobile,Fax,Email1,Email2,Email3,Notes) Values('" + this.txtTitle.Text + "','" + this.txtInitials.Text + "','" + this.txtFirstname.Text + "','" + this.txtLastname.Text + "','" + this.txtHomeNumber.Text + "','" + this.txtMobile.Text + "','" + this.txtWorkNumber.Text + "','" + this.txtFax.Text + "','" + email1 + "','" + email2 + "','" + email3 + "','" + this.txtNotes.Text + "')"; OleDbCommand cmd = new OleDbCommand(sql,cnn); try { cnn.Open(); cmd.ExecuteNonQuery(); how do i build the string correctly?????
-
Use quotes instead of apostrophes in the html code. But you should protect your code against SQL injections anyway. Otherwise you might be in for an unpleasent surprise... --- b { font-weight: normal; }
using quotes makes the string break up as there is a string within a string? ie newmail = "" + email.trim()+ ""; wont compile????
-
using quotes makes the string break up as there is a string within a string? ie newmail = "" + email.trim()+ ""; wont compile????
-
fantastic just what i neede worked a treat, goes into database lovely but now i need to tidy it up when i bring it back out as asp.net throughs a huge wobly when i try to save it on the page as it has charac it does not like so i think i need to get rid of the \ to display it back on the page, any ideas?
-
fantastic just what i neede worked a treat, goes into database lovely but now i need to tidy it up when i bring it back out as asp.net throughs a huge wobly when i try to save it on the page as it has charac it does not like so i think i need to get rid of the \ to display it back on the page, any ideas?
-
There isn't any \ in the string. The escape sequence \" just puts the character " into the string. What do you mean by "asp.net throughs a huge wobly"? Barely half of those are real words... --- b { font-weight: normal; }
i am trying to get asp.net make a hyperlink in a datalist so i need to put the whole maito: tag into the database so AS WHEN IT IS READ BACK OUT Again it create a mailto in the datalist. the data list is smart enough to convert the tag into html and work fine, but when the details are seen in a textbox on its own the whole of the mailto tag appears in the textbox and when you hit save asp.net goes crazy so it does not like things like this being saved test\"" saving that sort of text in a textbox to a database blows up!!! so i had to clean the text up from the database all is working well thanks to you.:)
-
i am trying to get asp.net make a hyperlink in a datalist so i need to put the whole maito: tag into the database so AS WHEN IT IS READ BACK OUT Again it create a mailto in the datalist. the data list is smart enough to convert the tag into html and work fine, but when the details are seen in a textbox on its own the whole of the mailto tag appears in the textbox and when you hit save asp.net goes crazy so it does not like things like this being saved test\"" saving that sort of text in a textbox to a database blows up!!! so i had to clean the text up from the database all is working well thanks to you.:)
robmays wrote: asp.net goes crazy robmays wrote: saving that sort of text in a textbox to a database blows up I assume that you don't mean what you write. As asp.net is not an intelligent being, it can hardly go crazy. I don't believe that saving some text can cause any sort of explosion either. So what do you mean? If you get an error message, it would be helpful if you shared it. Otherwise I can just keep guessing what's happening. robmays wrote: test\"" You have to use the pre tag for the code to show up in the post. --- b { font-weight: normal; }