MANTENIMIENTO DE UNA TABLA CON LISTBOX.
Enviado por monto2435 • 23 de Febrero de 2018 • 2.819 Palabras (12 Páginas) • 261 Visitas
...
stb.Append("Update Employees Set LastName='");
stb.Append(txtApellido.Text);
stb.Append("',FirstName='");
stb.Append(txtNombre.Text);
stb.Append("' Where EmployeeID=");
stb.Append(txtCodigo.Text);
con.Open();
cmd.CommandText = stb.ToString();
reg = cmd.ExecuteNonQuery();
if (reg
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (con.State == ConnectionState.Open) con.Close();
stb.Length = 0;
ListarEmpleados();
button2.Enabled = false;
}
}
Control: btnEliminar Evento: Click
private void button4_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(" ", con);
if (txtCodigo.Text != " ")
{
try
{
stb.Length = 0;
stb.Append("Delete From Employees Where EmployeeID=");
stb.Append(txtCodigo.Text);
con.Open();
cmd.CommandText = stb.ToString();
reg = cmd.ExecuteNonQuery();
if (reg
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (con.State == ConnectionState.Open) con.Close();
stb.Length = 0;
ListarEmpleados();
button2.Enabled = false;
}
}
}
create database northwind
use northwind
IF NOT EXISTS (SELECT * FROM dbo.sysusers WHERE name = N'guest')
EXEC dbo.sp_grantdbaccess @loginame = N'guest'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CustomerDemographics]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[CustomerDemographics](
[CustomerTypeID] [nchar](10) NOT NULL,
[CustomerDesc] [ntext] NULL,
CONSTRAINT [PK_CustomerDemographics] PRIMARY KEY NONCLUSTERED
(
[CustomerTypeID] ASC
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Region]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Region](
[RegionID] [int] NOT NULL,
[RegionDescription] [nchar](50) NOT NULL,
CONSTRAINT [PK_Region] PRIMARY KEY NONCLUSTERED
(
[RegionID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Employees]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Employees](
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[LastName] [nvarchar](20) NOT NULL,
[FirstName] [nvarchar](10) NOT NULL,
[Title] [nvarchar](30)
...