
Problema al Insertar nuevo registro
Publicado por Iraitz (1 intervención) el 28/07/2015 13:33:26
Hola de nuevo!
Traigo una nueva duda, y es que al intentar crear un nuevo registro en SQL a través de Vb.Net me salta un error: "Error al convertir el valor del parámetro de String a Guid", y me estoy volviendo loco!
Les dejo el código para que echen un vistazo.
Muchas Gracias por adelantado.
Traigo una nueva duda, y es que al intentar crear un nuevo registro en SQL a través de Vb.Net me salta un error: "Error al convertir el valor del parámetro de String a Guid", y me estoy volviendo loco!
Les dejo el código para que echen un vistazo.
Muchas Gracias por adelantado.
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuardar.Click
Dim auxComp As String = ""
Dim sCnn As String = "Server=" & Form1.cboInstancias.Text & "; " & _
"database=" & Form1.cboBases.Text & "; integrated security=yes"
MessageBox.Show("CreoConex")
Dim cnn As New SqlConnection
Dim sql As String = " insert into LineasReparacion values(@ClienteIdLR, @ProductoIdLR,@NSerie, @Cantidad, @NCR,@FechaRecepcion, @SAT,@FechaReparacion, @OrdenProduccion, @Posicion, @ListaMaterialesId, @FalloIdLR, @FalloFuncionalIdLR, @DescripcionLR, @TiempoEmpleado, @Garantia, @EmpleadoIdLR, @Observaciones, @Facturar, @FallosReparacion, @InformeReparacion)"
MessageBox.Show("Insert")
cnn = New SqlConnection(sCnn)
Dim cmd As New SqlCommand(sql, cnn)
Dim sqlClie As String = "SELECT ClienteId FROM Clientes WHERE ClienteCodigo = '" & txtClie.Text & "'"
Dim sqlProd As String = "SELECT ProductoId FROM Productos WHERE ProductoCodigo = '" & txtProd.Text & "'"
Dim sqlEmple As String = "SELECT EmpleadoId FROM Empleados WHERE EmpleadoCodigo = '" & cboEmple.Text & "'"
Dim sqlFallo As String = "SELECT FalloId FROM TiposFallo WHERE FalloCodigo = '" & cboMontaje.Text & "'"
Dim sqlFunc As String = "SELECT FalloFuncionalId FROM FallosFuncionales WHERE FalloFuncional = '" & cboFunc.Text & "'"
Dim sqlComp As String = "SELECT ListaMaterialesId FROM ListaMateriales WHERE ComponenteCodigo = '" & txtComp.Text & "'"
MessageBox.Show("SQLS")
Dim cmdClie As New SqlCommand(sqlClie, cnn)
Dim cmdProd As New SqlCommand(sqlProd, cnn)
Dim cmdEmple As New SqlCommand(sqlEmple, cnn)
Dim cmdFallo As New SqlCommand(sqlFallo, cnn)
Dim cmdFunc As New SqlCommand(sqlFunc, cnn)
Dim cmdComp As New SqlCommand(sqlComp, cnn)
MessageBox.Show("CreoCmd")
' Inicializar un nuevo SqlDataAdapter
Dim daClie As New SqlDataAdapter(cmdClie)
Dim daProd As New SqlDataAdapter(cmdProd)
Dim daEmple As New SqlDataAdapter(cmdEmple)
Dim daFallo As New SqlDataAdapter(cmdFallo)
Dim daFunc As New SqlDataAdapter(cmdFunc)
Dim daComp As New SqlDataAdapter(cmdComp)
MessageBox.Show("Creoda")
'Crear y Llenar un Dataset
Dim dsClie As New DataSet
Dim dsProd As New DataSet
Dim dsEmple As New DataSet
Dim dsFallo As New DataSet
Dim dsFunc As New DataSet
Dim dsComp As New DataSet
MessageBox.Show("Creods")
daClie.Fill(dsClie)
daProd.Fill(dsProd)
daEmple.Fill(dsEmple)
daFallo.Fill(dsFallo)
daFunc.Fill(dsFunc)
daComp.Fill(dsComp)
MessageBox.Show("LLeno ds")
If (txtComp.Text = "") Then
auxComp = ""
End If
Try
MessageBox.Show("EntraTry")
cnn.Open()
MessageBox.Show("AbroConex")
cmd.CommandType = CommandType.Text
MessageBox.Show("Nose")
cmd.Parameters.Add(" @ClienteIdLR", SqlDbType.UniqueIdentifier).Value = dsClie.ToString
MessageBox.Show("1")
cmd.Parameters.Add(" @ProductoIdLR", SqlDbType.UniqueIdentifier).Value = dsProd.ToString
MessageBox.Show("2")
cmd.Parameters.Add(" @NSerie", SqlDbType.NVarChar, 32).Value = txtNSerie.Text
MessageBox.Show("3")
cmd.Parameters.Add(" @Cantidad", SqlDbType.Int).Value = txtCant.Text
MessageBox.Show("4")
cmd.Parameters.Add(" @NCR", SqlDbType.NChar, 50).Value = txtNCR.Text
MessageBox.Show("5")
cmd.Parameters.Add(" @FechaRecepcion", SqlDbType.DateTime).Value = txtFRec.Text
MessageBox.Show("6")
cmd.Parameters.Add(" @SAT", SqlDbType.Bit).Value = CBSAT.Checked
MessageBox.Show("7")
cmd.Parameters.Add(" @FechaReparacion", SqlDbType.DateTime).Value = txtFRep.Text
MessageBox.Show("8")
cmd.Parameters.Add(" @OrdenProduccion", SqlDbType.NVarChar, 50).Value = txtOProd.Text
MessageBox.Show("9")
cmd.Parameters.Add(" @Posicion", SqlDbType.NVarChar, 50).Value = txtPos.Text
MessageBox.Show("10")
If (auxComp <> "") Then
cmd.Parameters.Add(" @ListaMaterialesId", SqlDbType.UniqueIdentifier).Value = dsComp.ToString
MessageBox.Show("11")
Else
cmd.Parameters.Add(" @ListaMaterialesId", SqlDbType.UniqueIdentifier).Value = auxComp.ToString
MessageBox.Show("12")
End If
cmd.Parameters.Add(" @FalloId", SqlDbType.UniqueIdentifier).Value = dsFallo.ToString
MessageBox.Show("13")
cmd.Parameters.Add(" @FalloFuncional", SqlDbType.UniqueIdentifier).Value = dsFunc.ToString
MessageBox.Show("14")
cmd.Parameters.Add(" @Descripcion", SqlDbType.NVarChar, 1000).Value = rtbDesc.Text
MessageBox.Show("15")
cmd.Parameters.Add(" @TiempoEmpleado", SqlDbType.Float).Value = txtTiempo.Text
MessageBox.Show("16")
cmd.Parameters.Add(" @Garantia", SqlDbType.Bit).Value = CBGarantia.Checked
MessageBox.Show("17")
cmd.Parameters.Add(" @EmpleadoId", SqlDbType.UniqueIdentifier).Value = dsEmple.ToString
MessageBox.Show("18")
cmd.Parameters.Add(" @Observaciones", SqlDbType.NVarChar, 1000).Value = rtbObs.Text
MessageBox.Show("19")
cmd.Parameters.Add(" @Facturar", SqlDbType.NChar, 250).Value = txtFact.Text
MessageBox.Show("20")
cmd.Parameters.Add(" @FalloReparaciones", SqlDbType.NChar, 10).Value = cboCodFallo.Text
MessageBox.Show("21")
cmd.Parameters.Add(" @InformeReparacion", SqlDbType.NChar, 20).Value = txtInfo.Text
MessageBox.Show("22")
cmd.ExecuteNonQuery()
MessageBox.Show("NonQuery")
MessageBox.Show(" REGISTRO INSERTADO CORRECTAMENTE")
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, _
"error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
End Sub
Valora esta pregunta


0