ayuda sql y visual studio
Publicado por natalia (1 intervención) el 04/12/2014 20:38:11
hola como estan!! desde ya gracias!! tengo un problema con un programa , yo cree una base de datos en sql y y la codificacion en visual studio ... el alta me la genera correctamente pero me dan estos errores en la baja (por nombre) la modificacion (por id) y la consulta (por genero)
codigo baja
codigo baja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
using System.Data.SqlClient;
namespace videoclub
{ public partial class Form3 : Form {public Form3()
{InitializeComponent();
}private SqlConnection conexion;
private SqlDataAdapter adaptador;
private void Form3_Load(object sender, EventArgs e)
{conexion = new SqlConnection("Data Source=NETBOOK-PC\\SQLEXPRESS;Initial Catalog=videoclub;Integrated Security=True");
adaptador = new SqlDataAdapter();
SqlCommand baja = new SqlCommand("delete from pelicula where nombre_pelicula = @nombre", conexion);
adaptador.DeleteCommand = baja;
adaptador.DeleteCommand.Parameters.Add(new SqlParameter("@nombre", SqlDbType.VarChar));
}private void button2_Click(object sender, EventArgs e)
{adaptador.DeleteCommand.Parameters["@nombre"].Value = txtn.Text; // error no se encontro nullreferenceecepxion
try
{conexion.Open();
int cantidad = adaptador.DeleteCommand.ExecuteNonQuery();
if (cantidad == 0)
{MessageBox.Show("No existe");
}else
{MessageBox.Show("se Borro la pelicula con dicho nombre");
} }catch (SqlException exepcion)
{MessageBox.Show(exepcion.ToString());
}finally
{conexion.Close();
} }private void button1_Click(object sender, EventArgs e)
{Close();
} }}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Data;using System.Data.SqlClient;
using System.Windows.Forms;
namespace videoclub
{ public partial class Form4 : Form {public Form4()
{InitializeComponent();
}private SqlConnection conexion;
private SqlDataAdapter adaptador;
private void Form4_Load(Object sender, EventArgs e)
{conexion = new SqlConnection("Data Source=NETBOOK-PC\\SQLEXPRESS;Initial Catalog=videoclub;Integrated Security=True");
adaptador = new SqlDataAdapter();
SqlCommand modificar = new SqlCommand("update pelicula set id_pelicula=id, nombre_pelicula=@nombre, web_pelicula=@web, descripcion=@descripcion, anio=@anio, id_genero=@id_genero where id_pelicula=@id_pelicula", conexion);
adaptador.UpdateCommand = modificar;
adaptador.UpdateCommand.Parameters.Add(new SqlParameter("id_pelicula", SqlDbType.Int));
adaptador.UpdateCommand.Parameters.Add(new SqlParameter("nombre", SqlDbType.VarChar));
adaptador.UpdateCommand.Parameters.Add(new SqlParameter("web", SqlDbType.VarChar));
adaptador.UpdateCommand.Parameters.Add(new SqlParameter("descripcion", SqlDbType.VarChar));
adaptador.UpdateCommand.Parameters.Add(new SqlParameter("id_genero", SqlDbType.VarChar));
adaptador.UpdateCommand.Parameters.Add(new SqlParameter("anio", SqlDbType.Int));
}private void button1_Click(object sender, EventArgs e)
{Close();
}private void button2_Click(object sender, EventArgs e)
{adaptador.UpdateCommand.Parameters["@id_pelicula"].Value = txtid.Text; // error no se encontro nullreferenceecepxion
adaptador.UpdateCommand.Parameters["@nombre"].Value = txtn.Text;
adaptador.UpdateCommand.Parameters["@web"].Value = txtw.Text;
adaptador.UpdateCommand.Parameters["@descripcion"].Value = txtd.Text;
adaptador.UpdateCommand.Parameters["@idgenero_"].Value = cb.Text;
adaptador.UpdateCommand.Parameters["@anio"].Value = txta.Text;
try
{conexion.Open();
adaptador.UpdateCommand.ExecuteNonQuery();
}catch (SqlException exception)
{MessageBox.Show(exception.ToString());
MessageBox.Show("modificacion correcta");
}finally
{conexion.Close();
} }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.ComponentModel;using System.Data;using System.Data.SqlClient;
using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
namespace videoclub
{ public partial class Form5 : Form {public Form5()
{InitializeComponent();
}private void button1_Click(object sender, EventArgs e)
{Close();
}private SqlConnection conexion;
private SqlDataAdapter adaptador;
private DataSet datos;
private DataTable datos2;
private void Form5_Load(object sender, EventArgs e)
{conexion = new SqlConnection("Data Source=NETBOOK-PC\\SQLEXPRESS;Initial Catalog=videoclub;Integrated Security=True");
adaptador = new SqlDataAdapter();
SqlCommand consulta = new SqlCommand("select id_genero , genero, descripcion from genero", conexion);
//pase los datos de la tabla genero al combox
adaptador.SelectCommand =consulta;
datos = new DataSet();
adaptador.Fill(datos, "genero"); // error no se encontro sqlexepcion
comboBox1.DataSource = datos.Tables["genero"];
comboBox1.DisplayMember = datos.Tables["genero"].Columns["genero"].ToString();
comboBox1.ValueMember = datos.Tables["genero"].Columns["id_genero"].ToString();
comboBox1.ValueMember = datos.Tables["genero"].Columns["descripcion"].ToString();
//busco por el combox para mostrar en el datagrill mediante un procedimiento alamcenado
adaptador.SelectCommand = new SqlCommand("busquedaporgenero", conexion);
adaptador.SelectCommand.CommandType = CommandType.StoredProcedure;
adaptador.SelectCommand.Parameters.Add("id_genero", SqlDbType.VarChar);
}private void button2_Click(object sender, EventArgs e)
{datos2 = new DataTable();
adaptador.SelectCommand.Parameters["@id_genero"].Value = comboBox1.Text;
adaptador.Fill(datos2);
dataGridView1.DataSource = datos2;
} }}Valora esta pregunta


0