Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/05/2005, 05:32
Avatar de Nombela
Nombela
 
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 10 meses
Puntos: 1
Que te parece??

Que te parece esta forma de hacerlo:

int auto=0;
myConnection = new SqlConnection (connectionString);
myCommand = new SqlCommand ("SELECT Max(ServId) as Maximo FROM Servicios;",myConnection);
myCommand.Connection.Open();
SqlDataReader readermax = myCommand.ExecuteReader();
if (readermax.Read())
{
if (readermax["Maximo"]==null)
auto=1;
else
auto=Convert.ToInt16(readermax["Maximo"])+1;
}
myCommand.Connection.Close();
String insertCmd = "insert into Servicios (ServId, ServNombre, ServDescripcion, ServIdTipo) values (@id, @Nombre," +
" @Descripcion, @Tipo); insert into UsuariosServicios (UsSerIdUs,UsServIdServ) values (@Usuario, @id)";
myCommand = new SqlCommand(insertCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@Id",
SqlDbType.Int, 4));
myCommand.Parameters["@Id"].Value = auto;
myCommand.Parameters.Add(new SqlParameter("@Nombre",
SqlDbType.NVarChar, 50));
myCommand.Parameters["@Nombre"].Value = NuevoServNombre.Value;
myCommand.Parameters.Add(new SqlParameter("@Descripcion",
SqlDbType.NVarChar, 50));
myCommand.Parameters["@Descripcion"].Value = NuevoServDescripcion.Value;
myCommand.Parameters.Add(new SqlParameter("@Tipo",
SqlDbType.Int, 4));
myCommand.Parameters["@Tipo"].Value = NuevoComboTipo.SelectedItem.Value;
myCommand.Parameters.Add(new SqlParameter("@Usuario",
SqlDbType.Int, 4));
myCommand.Parameters["@Usuario"].Value = Request.QueryString["id"];
myCommand.Connection.Open();
try
{
if (NuevoServNombre.Value=="")
MsgBox1.alert("Debe de insertar el Nombre del servicio");
else if (NuevoServDescripcion.Value=="")
MsgBox1.alert("Debe de insertar la descripcion del servicio");
else
{
//myCommand.ExecuteNonQuery();
//Response.Redirect("MenuadministradorServicios.aspx ?Ok=1&Nombre="+Request.QueryString["Nombre"].ToString()+"&Id="+Request.QueryString["id"].ToString());
}
}