Visual Basic.NET - agregar datos a base de datos

 
Vista:
sin imagen de perfil

agregar datos a base de datos

Publicado por Fernando (25 intervenciones) el 13/06/2014 05:48:47
Hola a todos tengo un problema y por más que busco no encuentro la solución a ver si alguno me lo puede solucionar:

He hecho una base de datos SQLexpres con visual studio 2010 y tengo un formulario con una DataGrid y varios TextBox pongo datos en los TextBox y pulsando el botón salvar veo los datos en la DataGrid pero sigo sin conseguir que los datos se guarden en la bese de datos. Alguien me puede ayudar por favor.
Tengo 4 TextBox el botón Agregar y otro Salvar por sí hago alguna modificación en un registro me guarde los cambios sin que se repita el registro.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

agregar datos a base de datos

Publicado por snti (29 intervenciones) el 13/06/2014 13:47:02
Tenes el codigo del boton salvar?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

agregar datos a base de datos

Publicado por Fernando (25 intervenciones) el 13/06/2014 19:34:50
Tengo varios codigos que he probado pero ninguno me guarda los nuevos registros en la base de datos y son estos.
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
Imports System.Data.SqlClient
 
Public Class Form2
    Dim row(4) As String
 
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'Database1DataSet1.BARCINO' Puede moverla o quitarla según sea necesario.
        Me.BARCINOTableAdapter.Fill(Me.Database1DataSet1.BARCINO)
 
        Button1.Text = "Salir"
        Button2.Text = "Guardar"
        Button3.Text = "Modificar"
        Button4.Text = "Eliminar"
        DataGridView1.ColumnCount = 4
        DataGridView1.Columns(0).Name = "Fabricante"
        DataGridView1.Columns(1).Name = "Modelo"
        DataGridView1.Columns(2).Name = "Denominacion del Recambio"
        DataGridView1.Columns(3).Name = "Referencia"
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        BARCINOBindingSource.AddNew()
        BARCINOBindingSource.Current("fabricante") = TextBox4.Text
        BARCINOBindingSource.Current("modelo") = TextBox3.Text
        BARCINOBindingSource.Current("denominación del recambio") = TextBox2.Text
        BARCINOBindingSource.Current("referencia") = TextBox1.Text
        TextBox4.Text = ""
        TextBox3.Text = ""
        TextBox2.Text = ""
        TextBox1.Text = ""
        Me.Validate()
        BARCINOBindingSource.EndEdit()
        BARCINOTableAdapter.Update(Database1DataSet1.BARCINO)
    End Sub


Este es otro codigo.

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
Imports System.Data.SqlClient
Public Class Form3
    Dim row(4) As String
 
        Private Property Queryable As String
 
        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'Database1DataSet1.CIUTADELLA' Puede moverla o quitarla según sea necesario.
        Me.CIUTADELLATableAdapter.Fill(Me.Database1DataSet1.CIUTADELLA)
            Button1.Text = "Salir"
            Button2.Text = "Guardar"
            Button3.Text = "Modificar"
            Button4.Text = "Eliminar"
            DataGridView1.ColumnCount = 4
            DataGridView1.Columns(0).Name = "Fabricante"
            DataGridView1.Columns(1).Name = "Modelo"
            DataGridView1.Columns(2).Name = "Denominación del Recambio"
            DataGridView1.Columns(3).Name = "Referencia"
        End Sub
 
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim fila As DataRow =
Me.Database1DataSet1.CIUTADELLA.NewRow()
        'fila(0) = codigo autogenerado por lo tanto no lo asignamos  
        fila(0) = Me.TextBox4.Text 'Nombre de la categoria
        fila(1) = Me.TextBox3.Text 'Nombre de la categoria
        fila(2) = Me.TextBox2.Text 'Nombre de la categoria
        fila(3) = Me.TextBox1.Text 'Nombre de la categoria
        Me.Database1DataSet1.CIUTADELLA.Rows.Add(fila)
 
        'Hasta acá se agregaron los datos, pero sólo en el DATASET
 
        TextBox4.Text = ""
        TextBox3.Text = ""
        TextBox2.Text = ""
        TextBox1.Text = ""
 
        'Actualizamos los cambios en la BD, metodo UPDATE 
 
        Me.CIUTADELLATableAdapter.Update(Me.Database1DataSet1.CIUTADELLA)
 
        Me.Validate()
    End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar