您好,首先感谢您的阅读。 我在.txt文件中通过“ExecuteNonQuery”执行查询以验证表是否存在等。
当我尝试从.txt文件中收集“ñ”字符并在ExecuteNonQuery中执行此操作时出现问题(如果我将查询放入Sql Server Management Studio中,则可以使用)。 我必须使用这个字符,因为它包含在列的名称'año'中,这意味着'年'的英文。
PD:我试过puttin'& ntilde'并且它有效,ExecuteNonQuery没有给我任何错误,但是SqlServer无法识别它。最后,我在.txt文件中留下了一个小例子:
CREATE TABLE[dbo].[autos](
id_auto int IDENTITY(1, 1) not null PRIMARY KEY,
patente varchar(7) not null,
marca varchar(12) not null,
modelo varchar(12) not null,
año int not null,
comentarios_auto varchar(200),
fecha_registro date DEFAULT GetDate() not null)
C#中的代码:
int counter = 0;
string linea;
string contenedor_texto;
contenedor_texto = "";
StreamReader file = new StreamReader("c:/Users/Natario/Desktop/test.txt");
while ((linea = file.ReadLine()) != null)
{
contenedor_texto = contenedor_texto + linea;
counter++;
}
string comando_consulta = contenedor_texto;
comandoSQLbeta(comando_consulta,datosConexion);
PD2:comandoSQLbeta,只执行包含'comando_consulta'的SQLQuery。 PD3:参数'datosConexion'是一个包含connectionString
的字符串答案 0 :(得分:1)
使用方括号来转义除拉丁语以外的字母字符的名称:
public class OutboundController : ApiController {
public HttpResponseMessage Post([FromUri] int id, [FromBody] OutboundData outboundData) {
MicrosoftAppCredentials.TrustServiceUrl(outboundData.ServiceUrl);
//create conversation
var connector = new ConnectorClient(new Uri(outboundData.ServiceUrl));
var botAccount = new ChannelAccount { Id = outboundData.FromAccountId, Name = outboundData.FromAccountName };
var toAccount = new ChannelAccount { Id = outboundData.ToAccountId, Name = outboundData.ToAccountName };
if(!MicrosoftAppCredentials.IsTrustedServiceUrl(outboundData.ServiceUrl)) {
throw new Exception("service URL is not trusted!");
}
var conversationResponse = connector.Conversations.CreateDirectConversation(botAccount, toAccount);
var client = new BuslogicClient();
var confirmData = client.GetOutboundData(id);
var greetingMessage = CreateGreetingMessage(confirmData);
var convoMessage = Activity.CreateMessageActivity();
convoMessage.Text = greetingMessage;
convoMessage.From = botAccount;
convoMessage.Recipient = toAccount;
convoMessage.Conversation = new ConversationAccount(id: conversationResponse.Id);
convoMessage.Locale = "en-Us";
connector.Conversations.SendToConversationAsync((Activity)convoMessage);
string message = string.Format("I received correlationid:{0} and started conversationId:{1}", id, conversationResponse.Id);
var response = Request.CreateResponse(HttpStatusCode.OK, message);
return response;
}