
12/05/2005, 02:45
|
 | | | Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 10 meses Puntos: 1 | |
Transacciones Ya he conseguido implementar lo de las transacciones que me dijo Jose, aqui os lo dejo para lo que os haga falta:
private void CambiaServicios(string []arr)
{
SqlTransaction transaccion;
myConnection = new SqlConnection (connectionString);
string updateCmd;
myConnection.Open();
transaccion=myConnection.BeginTransaction();
if (ConfUsPass.Visible)
{
updateCmd = "UPDATE Usuarios SET UsNombre=@UsNombre,UsPass=@UsPass,UsMail=@UsMail,U sTelefono=@UsTelefono,UsIdPer=@UsIdPer where UsId=@UsId";
}
else
{
updateCmd = "UPDATE Usuarios SET UsNombre=@UsNombre,UsMail=@UsMail,UsTelefono=@UsTe lefono,UsIdPer=@UsIdPer where UsId=@UsId; ";
}
//myCommand.Connection.Open();
myCommand = new SqlCommand(updateCmd, myConnection);
myCommand.Transaction=transaccion;
myCommand.Parameters.Add(new SqlParameter("@UsId",
SqlDbType.Int, 4));
myCommand.Parameters["@UsId"].Value = ComboLogin.SelectedItem.Value;
myCommand.Parameters.Add(new SqlParameter("@UsNombre",
SqlDbType.NVarChar, 50));
myCommand.Parameters["@UsNombre"].Value = UsNombre.Value;
myCommand.Parameters.Add(new SqlParameter("@UsPass",
SqlDbType.NVarChar, 50));
myCommand.Parameters["@UsPass"].Value = UsPass.Value;
myCommand.Parameters.Add(new SqlParameter("@UsMail",
SqlDbType.NVarChar, 50));
myCommand.Parameters["@UsMail"].Value = UsMail.Value;
myCommand.Parameters.Add(new SqlParameter("@UsTelefono",
SqlDbType.NVarChar, 15));
myCommand.Parameters["@UsTelefono"].Value = UsTelefono.Value;
myCommand.Parameters.Add(new SqlParameter("@UsIdPer",
SqlDbType.Int, 4));
myCommand.Parameters["@UsIdPer"].Value = UsPerfil.SelectedItem.Value;
try
{
if ((ConfUsPass.Visible) && (UsPass.Value!=ConfUsPass.Value))
MsgBox1.alert("El password no es correcto");
/*else
{
//int numreg=myCommand.ExecuteNonQuery();
//updateservicios();
//Response.Redirect("MenuadministradorUsu.aspx?Oku=1 &Nombre="+Request.QueryString["Nombre"].ToString()+"&Id="+Request.QueryString["id"].ToString()+"&mod="+ComboLogin.SelectedItem.Value) ;
//Response.Redirect("Menuadministrador1.aspx?Oku=1&m od="+nombre.Text);
}*/
//myCommand.Connection.Close();
string sql=String.Empty;
/*int i=1;
while (i< arr.Length)
{
if (i==1)
{
sql = " where UsServIdServ<>" + arr[i];
}
else
{
sql += " and UsServIdServ<>" + arr[i];
}
i+=1;
}*/
//myCommand.Connection.Open();
//myCommand.CommandText = "";
sql = "Delete from UsuariosServicios WHERE (UsServIdUs = "+ComboLogin.SelectedItem.Value+");";// + sql + " and UsServIdUs=" + ComboLogin.SelectedItem.Value+";";
myCommand.CommandText += sql;
//myCommand.Connection.Close();
int i=1;
while (i< arr.Length)
{
if (Convert.ToString(ViewState["identificadores"]).IndexOf(arr[Convert.ToInt16(i)])!=-1)
{
//Response.Write("HOLA");
}
else
{
myCommand.CommandText += " Insert into UsuariosServicios (UsServIdServ,UsServIdUs) values (" + arr[i] +"," + ComboLogin.SelectedItem.Value +");";
}
i+=1;
}
//myCommand.Connection.Open();
//Response.Write(myCommand.CommandText);
int numreg1=myCommand.ExecuteNonQuery();
transaccion.Commit();
myCommand.Connection.Close();
Response.Redirect("MenuadministradorUsu.aspx?Oku=1 &Nombre="+Request.QueryString["Nombre"].ToString()+"&Id="+Request.QueryString["id"].ToString()+"&mod="+ComboLogin.SelectedItem.Value) ;
}
catch (SqlException c)
{
transaccion.Rollback();
myCommand.Connection.Close();
if (c.Number == 2627)
mensage.Text = "ERROR: Este cliente ya existe";
else
mensage.Text = "ERROR: No se ha podido añadir el registro, por favor " +
"asegurese de que todo esta correctamente escrito, gracias";
}
}
ahora me keda ver como soluciono lo de que se borra el input. |