I really don't know what to do. Could you please help me?
What I'm trying to do is that when a person watns to modify his data shown at screen taken from the DataBase when they finish modifing they click in a button and that's where the stored procedure comes in a checks if the data was modified it updates but if it isn't modified...well it doesn't modify the DataBase BUT when i run the proyect it just doesn't work.
The funny thing is that the Stored Procedure works at SQLServer but at C# won't.
Here's my code:
Stored Procedure:
Create Procedure SP_PDF
(@nombre varchar(50), @tel int, @dir varchar(50), @rfc char(13))
as
declare @cont int
set @cont = 0
while(@cont < 4)
Begin
if((select nombre from cat_cliente where rfc = @rfc) != @nombre)
Begin
update cat_cliente set nombre = @nombre
End
else
Begin
set @cont += 1
End
if((select telefono from cat_cliente where rfc = @rfc) != @tel)
Begin
update cat_cliente set telefono = @tel
End
else
Begin
set @cont += 1
End
if((select direccion from cat_cliente where rfc = @rfc) != @dir)
Begin
update cat_cliente set direccion = @dir
End
else
Begin
set @cont += 1
End
End
C#:
String query = "exec SP_PDF @nombre, @tel, @dir, @rfc";
SqlCommand cmd = new SqlCommand(query, cnx);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@nombre", SqlDbType.VarChar).Value = Nombre.Text;
cmd.Parameters.AddWithValue("@tel", SqlDbType.Int).Value = Telefono.Text;
cmd.Parameters.AddWithValue("@dir", SqlDbType.VarChar).Value = Direccion.Text;
cmd.Parameters.AddWithValue("@rfc", SqlDbType.Char).Value = RFC.Text;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet set = new DataSet();
try
{
cnx.Open();
cmd.ExecuteNonQuery();
adp.Fill(set);
Response.Write("<script>window.alert('¡Funciono!');</script>");
}
catch (Exception ex)
{
throw ex;
}
finally
{
cnx.Close();
}
it just doesn't work!!! try to debug and find any exceptions.catch, does it get hit? If so, what is the exception?