الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة في اضافة نص لجدول msaccess

مغلق
بدأه aaaaaForum في 7 أبريل 2006 · 2 رد · 526 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

عندما اضيف نص عادي ل textbox الاضافه تعمل بدون مشاكل.

المشكلة هي عندما اضيف نص به اشارات خاصه مثل javascript او اشارات مثل : ', <, >, " ...

تظهر لي صفحة الخطاء هذه :

Server Error in '/' Application.

--------------------------------------------------------------------------------

Syntax error (missing operator) in query expression ''<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">RegisterClientScriptBlock("myscript","<script language='javascript'>alert(' World!')<'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression ''<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">RegisterClientScriptBlock("myscript","<script language='javascript'>alert(' World!')<'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

#2
public string parsetext(string text, bool allow)
  {
 	 StringBuilder sb = new StringBuilder(text);
 	 sb.Replace("  ","  ");
 	 sb.Replace("[","<");
 	 sb.Replace("]",">");
 	 
 	 if(!allow)
 	 { 
    sb.Replace("<","<");
    sb.Replace(">",">");
    sb.Replace("\"",""");
 	 } 
 	 StringReader sr = new StringReader(sb.ToString());
 	 StringWriter sw = new StringWriter();
 	 while(sr.Peek()>-1)
 	 {
    string temp = sr.ReadLine();
    sw.Write(temp+"<br>");
 	 } 
 	 return sw.GetStringBuilder().ToString();
  }

وبعدين في الكلاس الي بيرسل للداتا بيز اكتب

sqlcom.Parameters.Add(new SqlParameter("@topic_poster",SqlDbType.Text));
    sqlcom.Parameters["@topic_poster"].Value=parsetext(this.postingtextBox.Text.ToString(),true);

دي اهم خطوة

parsetext(this.postingtextBox.Text.ToString(),true);

المكتوب بالازرق دة اسم الكلاس المعمول في الاول

والاحمر دة اسم التكست بوكس

وممكن بالاطريقة دى تعمل بحث لكلمات معينة وتغيرها بكلمات اخراى

#3

شكرا اخي الكريم عل المساعدة

لقد اخذت الفكرة واضفت هذا الكود وهو يعمل تمام

string strBody=txtBody.Text.Replace("'","`");

هذا الموضوع مغلق.

مواضيع مشابهة