Error converting varchar data types to int

0
string cmd = string.Format("EXEC GuardarUsuario '{0}','{1}','{2}','{3}','{4}','{5}','{6}'", txtNom.Text.Trim(), txtApe.Text.Trim(), txtMail.Text.Trim(), txtUsu.Text.Trim(), txtPass.Text.Trim(), timeAlta.Text.Trim(), timeBaja.Text.Trim());
Utilidades.Ejecutar(cmd);
MessageBox.Show("se ha guardado correctamente");
return true;

When I execute that line in my Visual Studio, it throws me that error that I show in image, but I do not know where I'm wrong because I think I converted them well.

    
asked by Juanmaa14 01.10.2018 в 23:51
source

1 answer

0

This error looks like some of the parameters that you are passing to the procedure is a text and the procedure asks for an integer, check the 6 parameters that are correct:

"EXEC SaveUser '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}'"

On the other hand if you want to avoid errors if you are using C # 6 you can build the string in the following way:

$ "EXEC SaveUser '{txtNom.Text.Trim ()}', '{txtApe.Text.Trim ()}', '{txtMail.Text.Trim ()}', '{txtUsu.Text.Trim ()} ',' {txtPass.Text.Trim ()}, '{timeAlta.Text.Trim ()}', '{timeBaja.Text.Trim ()}' "

    
answered by 02.10.2018 в 13:34