Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Probleme mit einem Insert Into Befehl in VB.net

Empfohlene Antworten

Veröffentlicht

hi leute,

folgendes problem liegt vor:

Ich habe eine lokale sqlce DB vorliegen.

Diese wird benutzt um die Emails in plain sowie html from zu speichern. Die Abfrage sieht in etwa so aus :


 cmd.CommandText = "INSERT INTO Posteingang(Absender, Betreff, Datum, Größe, Inhalt, htmlbool, htmlinhalt) Values('" & from & "', '" & subject & _

                "', '" & [date] & "', '" & sizeText & "', '" & textbody & "', '" & IIf(htmlbody IsNot Nothing, "True", "False") & "', '" & IIf(htmlbody IsNot Nothing, htmlbody, Nothing) & "')"

So nun bekomme ich bei manchen Mailtexten folgenden fehler:

Fehler beim Analysieren der Abfrage.[Token line number = 1185, Token line offset = 352, Token in error = t]

Der fehler sagt mir leider wenig, was ich vermute ist, das im html text folgendes Zeichen enthalten ist (') welches verständlicherweise zu problemen bei der Abfrage führt, da die Werte durch (') getrennt werden.

Ich wage mich daran erinnern zu können das es eine möglichkeit gibt die stringvariable so zu modifizieren das der sql befehl alle zeichen im string ignoriert und diese einfach in die dafür vorgesehene Column speichert.

Wenn ich falsch liege korrigiert mich bitte, wie gesagt der Fehler sagt mir wenig deswegen stelle ich nur vermutungen an.

Lg

Gateway

Stichwort: "Parametrisierte Abfragen"

Hier findest du was dazu: Verhinderung von SQL Injection Marke .NET

Es geht zwar um SQL-Injection aber ist praktisch genau dein Problem ;)

  • Autor

Danke dir,

habe bereits eine Lösung. Hier ein beispiel für VB.NET :


  Dim nr As String = TextBox1.Text

        cmd1.CommandText = "INSERT INTO Test(Inhalt)VALUES (@nr)"

        cmd1.Parameters.AddWithValue("nr", nr)

        Con.Open()

        cmd1.ExecuteNonQuery()

        Con.Close()

lg

Gateway

no no no

pls good code writer

cmd.CommandText = "INSERT INTO Posteingang(Absender, Betreff, Datum, Größe, Inhalt, htmlbool, htmlinhalt) Values('" & from & "', '" & subject & _

"', '" & [date] & "', '" & sizeText & "', '" & textbody & "', '" & IIf(htmlbody IsNot Nothing, "True", "False") & "', '" & IIf(htmlbody IsNot Nothing, htmlbody, Nothing) & "')"

erorr

[date] date.text or date

IIf(htmlbody IsNot Nothing, "True", "False")

IIf(htmlbody IsNot Nothing, htmlbody, Nothing)

yes code

string AyarKayittarih = kayittarih.ToString("dd/MM/yyyy");

baglantitable.Sorgu_Calistir("insert into Sikayet(Eden,Tel,firma,Tarih,Gtarih,acikla,onay) values('"+ TextBox1.Text +"','"+TextBox2.Text+"','"+TextBox3.Text +"','"+ DropDownList7.SelectedValue +"','"+ AyarKayittarih+"','"+TextBox4.Text+"','"+ onaybekle +"' )");

good boy

class

public static void Sorgu_Calistir(string sql)

{

MySqlCommand sqlCommand = new MySqlCommand(sql, sqlBaglanti);

if (sqlCommand.Connection.State == ConnectionState.Closed)

{

sqlBaglanti.Open();

}

sqlCommand.ExecuteNonQuery();

sqlBaglanti.Close();

}

------

no no no

pls good code writer

cmd.CommandText = "INSERT INTO Posteingang(Absender, Betreff, Datum, Größe, Inhalt, htmlbool, htmlinhalt) Values('" & from & "', '" & subject & _

"', '" & [date] & "', '" & sizeText & "', '" & textbody & "', '" & IIf(htmlbody IsNot Nothing, "True", "False") & "', '" & IIf(htmlbody IsNot Nothing, htmlbody, Nothing) & "')"

erorr

[date] date.text or date

IIf(htmlbody IsNot Nothing, "True", "False")

IIf(htmlbody IsNot Nothing, htmlbody, Nothing)

yes code

string AyarKayittarih = kayittarih.ToString("dd/MM/yyyy");

baglantitable.Sorgu_Calistir("insert into Sikayet(Eden,Tel,firma,Tarih,Gtarih,acikla,onay) values('"+ TextBox1.Text +"','"+TextBox2.Text+"','"+TextBox3.Text +"','"+ DropDownList7.SelectedValue +"','"+ AyarKayittarih+"','"+TextBox4.Text+"','"+ onaybekle +"' )");

good boy

class

public static void Sorgu_Calistir(string sql)

{

MySqlCommand sqlCommand = new MySqlCommand(sql, sqlBaglanti);

if (sqlCommand.Connection.State == ConnectionState.Closed)

{

sqlBaglanti.Open();

}

sqlCommand.ExecuteNonQuery();

sqlBaglanti.Close();

}

------

Convert VB to C# or C# to VB Code Converter | Provided by Telerik

  • Autor
no no no

pls good code writer

cmd.CommandText = "INSERT INTO Posteingang(Absender, Betreff, Datum, Größe, Inhalt, htmlbool, htmlinhalt) Values('" & from & "', '" & subject & _

"', '" & [date] & "', '" & sizeText & "', '" & textbody & "', '" & IIf(htmlbody IsNot Nothing, "True", "False") & "', '" & IIf(htmlbody IsNot Nothing, htmlbody, Nothing) & "')"

erorr

[date] date.text or date

IIf(htmlbody IsNot Nothing, "True", "False")

IIf(htmlbody IsNot Nothing, htmlbody, Nothing)

yes code

string AyarKayittarih = kayittarih.ToString("dd/MM/yyyy");

baglantitable.Sorgu_Calistir("insert into Sikayet(Eden,Tel,firma,Tarih,Gtarih,acikla,onay) values('"+ TextBox1.Text +"','"+TextBox2.Text+"','"+TextBox3.Text +"','"+ DropDownList7.SelectedValue +"','"+ AyarKayittarih+"','"+TextBox4.Text+"','"+ onaybekle +"' )");

good boy

class

public static void Sorgu_Calistir(string sql)

{

MySqlCommand sqlCommand = new MySqlCommand(sql, sqlBaglanti);

if (sqlCommand.Connection.State == ConnectionState.Closed)

{

sqlBaglanti.Open();

}

sqlCommand.ExecuteNonQuery();

sqlBaglanti.Close();

}

------

I think in this situation the IIF function is the better way. But at least i made it much different.

But thank you anyway ;).

Greets,

Gateway

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.