Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem in using C# with VFP Data
Message
 
À
12/05/2007 07:51:19
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Divers
Thread ID:
01224919
Message ID:
01224934
Vues:
31
>>>Hello all,
>>>
>>>I have a problem updating a VFP table from C# code, whenever i try to pass text from a multiline textbox to a VFP memo field.
>>>
>>>When i execute the following code:
>>>
>>>_comando.CommandType = CommandType.Text;
>>>_comando.Connection = _connection;
>>>_comando.CommandText = _text;
>>>_comando.ExecuteNonQuery();
>>>
>>>where _text = "update _table set datamov = {^2007/05/12}, horai = '08:00' nao_conf = 'line1 line2', normas = 'line 1' where numero = 125 and nitem = 1"
>>>
>>>At _comando.ExecuteNonQuery() i got this error: "Command contains unrecognized phrase/keyword."
>>>
>>>The problem is in the sentence "nao_conf = 'line1 line2'", if i go back to the multiline textbox and delete de 2nd line the error does not happens.
>>>
>>>The VFP table field 'normas' is also a memo field, filled with data from a multiline textbox, but as i put only a line of text, i got no error. If i put 2 or more lines i would get the same error.
>>>
>>>If i go to a VFP command line and execute this code i get no error, is obvious. The problem is at the way C# builds the string or in the VfpOleDb.
>>>
>>>Does anybody knows why? And how to solve this?
>>>
>>>TIA,
>>>Joaquim
>>>Joaquim
>>
>>Pete is right with the embeded carriage return, line feed causing the problem. One solution is to pass the values using a parameterized update. Here is an example for updating a vfp table.
>>
>>OleDbConnection conn = _Connection_;
>>OleDbCommand Cmd = new OleDbCommand();
>>Cmd.Connection = conn;
>>Cmd.Parameters.Add("HEADER", OleDbType.Char);
>>Cmd.Parameters.Add("TEXT", OleDbType.VarChar);
>>Cmd.Parameters.Add("ID", OleDbType.VarChar);
>>Cmd.Parameters["HEADER"].Value = ps_header;
>>Cmd.Parameters["TEXT"].Value = ps_text;
>>Cmd.Parameters["ID"].Value = ps_id;
>>sql = "UPDATE calhead SET HEADER = ?, TEXT = ? WHERE ID = ?";
>>Cmd.CommandText = sql;
>>Cmd.ExecuteNonQuery();
>
>Thank you Michael,
>
>I've solved the problem creating a method that replaces the '\r\n' string with 'chr(13)+chr(10)', but think your solution is better.
>
>Joaquim

You may still have problems with other characters such as single quote (') in the text or if the length of the text exceeds 255 characters. Also, if you build an update statement is this manner your code is open to sql injection attacks. It is best to always pass the values as parameters to prevent these types of problems.
Michael McLain
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform