Foros del Web » Programación para mayores de 30 ;) » .NET »

hola nesecito ayuda urgente

Estas en el tema de hola nesecito ayuda urgente en el foro de .NET en Foros del Web. Imports System.Data.SqlClient Public Class Form1 Public Connection As New SqlConnection("Data Source=OSCAR-B\SQLEXPRESS;Initial Catalog=DBPRUEBA;Persist Security Info=True;User ID=sa;Password=administrador") Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ...
  #1 (permalink)  
Antiguo 04/07/2010, 19:37
Avatar de sanctusbellicosus91  
Fecha de Ingreso: marzo-2010
Mensajes: 23
Antigüedad: 14 años, 1 mes
Puntos: 0
hola nesecito ayuda urgente

Imports System.Data.SqlClient

Public Class Form1



Public Connection As New SqlConnection("Data Source=OSCAR-B\SQLEXPRESS;Initial Catalog=DBPRUEBA;Persist Security Info=True;User ID=sa;Password=administrador")
Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
If Me.txtNombre.Text <> "" Then
If Me.cbxEmpleo.Text <> "" Then
Me.dgvEjemplo.Rows.Add(Me.txtNombre.Text, Me.cbxEmpleo.Text)
Me.txtNombre.Text = ""
Me.cbxEmpleo.Text = ""

Else
MessageBox.Show("Ingrese un deporte", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
MessageBox.Show("Ingrese un nombre", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub

Private Sub dgvEjemplo_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvEjemplo.CellContentClick
If dgvEjemplo.Columns(e.ColumnIndex).Name = "Eliminar" Then
dgvEjemplo.Rows.RemoveAt(e.RowIndex)
End If
End Sub

Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuardar.Click
If dgvEjemplo.Rows.Count > 0 Then
Dim SqlString As String = ""
Dim ListSqlStrings As New ArrayList
For i As Integer = 0 To dgvEjemplo.Rows.Count - 1

SqlString = "INSERT INTO datos (nombre,deporte,fecha_inscripcion) VALUES ('" + dgvEjemplo.Rows(i).Cells(0).Value.ToString() + "','" + dgvEjemplo.Rows(i).Cells(1).Value.ToString() + "','" + dgvEjemplo.Rows(i).Cells(2).Value.ToString() + "')"

ListSqlStrings.Add(SqlString)
Next
If EjecutarTransaccion(ListSqlStrings) Then
MessageBox.Show("Info. guardada correctamente")
Close()
Else
MessageBox.Show("La Info. no se guardo")
End If
Else
MessageBox.Show("No hay informacion para guardar")
End If
End Sub
Public Function AbrirConexion() As Boolean
Dim band As Boolean = False
Try
Connection.Open()
band = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return band
End Function
Public Function CerrarConexion() As Boolean
Dim band As Boolean = False
Try
Connection.Close()
band = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return band
End Function
Public Function EjecutarTransaccion(ByVal ListaSentencias As ArrayList) As Boolean
Dim band As Boolean = False
If AbrirConexion() Then
Dim command As SqlCommand = Connection.CreateCommand()
Dim transaction As SqlTransaction
Dim strSentencia As Object
Dim sentencia As String = ""
transaction = Connection.BeginTransaction()
command.Connection = Connection
command.Transaction = transaction
Try
For Each strSentencia In ListaSentencias
sentencia = strSentencia.ToString()
command.CommandText = sentencia.ToString()
command.ExecuteNonQuery()
Next
transaction.Commit()
band = True
Catch ex As Exception
MessageBox.Show(ex.Message)
Try
transaction.Rollback()
Catch ex2 As Exception
MessageBox.Show(ex2.Message)
End Try
Finally
CerrarConexion()
End Try
End If
Return band
End Function
End Class



__________________________________________________ _______________


como le cambio a Msyql o como puedo enlazar ya q me marca este error



SqlString = "INSERT INTO datos (nombre,empleo) VALUES ('" + dgvEjemplo.Rows(i).Cells(0).Value.ToString() + "','" + dgvEjemplo.Rows(i).Cells(1).Value.ToString() + "','" + dgvEjemplo.Rows(i).Cells(2).Value.ToString() + "')"


El índice estaba fuera del intervalo. Debe ser un valor no negativo e inferior al tamaño de la colección. Nombre del parámetro: index




ayuda porfa
  #2 (permalink)  
Antiguo 04/07/2010, 21:11
 
Fecha de Ingreso: abril-2010
Mensajes: 89
Antigüedad: 14 años
Puntos: 1
Respuesta: hola nesecito ayuda urgente

puede que el valor del campo es pequeño y debas modificarlo

Etiquetas: hola
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:11.