简体   繁体   English

我无法插入SQL Server数据库

[英]I can't insert into SQL Server database

My code below: 我的代码如下:

public void InsertarClienteBD(int intCedula, string strNombre, string strApellido, string strTelefono, string strDireccion)
{
    SqlConnection cnnConexion = ObtenerConexion();
    string strSentenciaSQL = "insert into Clientes (cedula, nombre, apellido, telefono, direccion) values ({0}, {1}, {2}, {3}, {4}) ";
   strSentenciaSQL = string.Format(strSentenciaSQL, intCedula, strNombre, strApellido, strTelefono, strDireccion);
    SqlCommand cmdComando = new SqlCommand(strSentenciaSQL, cnnConexion); 
    cmdComando.ExecuteNonQuery();

    cnnConexion.Close();
}

I got below error: 我遇到以下错误:

An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll System.Web.Services.dll中发生了类型为'System.Web.Services.Protocols.SoapException'的未处理异常

Additional information: System.Web.Services.Protocols.SoapException 附加信息:System.Web.Services.Protocols.SoapException

First I would check the values that you are passing to see if they are the proper data type for each field. 首先,我将检查您传递的值,以查看它们是否是每个字段的正确数据类型。

Second I would look at using parameters with your query as marc_s suggested. 其次,我将按照marc_s的建议在查询中使用参数。 That would clear up any data type issue you may be having. 这样可以解决您可能遇到的任何数据类型问题。 For example: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters(v=vs.100).aspx 例如: https : //msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlcommand.parameters(v=vs.100).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM