Opcion1: Utilizando Dataset sin DataMember
Imports System.Data.SqlClient
Public Class Form1
Dim cnn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=imagen;Integrated Security=True")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
cnn.Open()
Dim sql As New SqlDataAdapter("select * from img", cnn)
Dim da As New DataSet
sql.Fill(da)
bs.DataSource = da.tables(0)
BindingNavigator1.BindingSource = bs
DataGridView1.DataSource = bs
TextBox1.DataBindings.Add("text", bs, "nombre")
TextBox2.DataBindings.Add("text", bs, "comentarios")
TextBox3.DataBindings.Add("text", bs, "ruta")
With cnn
If .State = ConnectionState.Open Then
.Close()
End If
.Dispose()
End With
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class
Opcion 2: Utilizando Dataset con dataMember
Imports System.Data.SqlClient
Public Class Form1
Dim cnn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=imagen;Integrated Security=True")
Dim bs As New BindingSource
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
cnn.Open()
Dim sql As New SqlDataAdapter("select * from img", cnn)
Dim da As New DataSet
sql.Fill(da, "maestro")
bs.DataSource = da
bs.DataMember = "maestro"
BindingNavigator1.BindingSource = bs
DataGridView1.DataSource = bs
TextBox1.DataBindings.Add("text", bs, "nombre")
TextBox2.DataBindings.Add("text", bs, "comentarios")
TextBox3.DataBindings.Add("text", bs, "ruta")
With cnn
If .State = ConnectionState.Open Then
.Close()
End If
.Dispose()
End With
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class
Opcion 3: Utilizando dataTable
Imports System.Data.SqlClient
Public Class Form1
Dim cnn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=imagen;Integrated Security=True")
Dim bs As New BindingSource
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
cnn.Open()
Dim sql As New SqlDataAdapter("select * from img", cnn)
Dim da As New DataTable
sql.Fill(da)
bs.DataSource = da
BindingNavigator1.BindingSource = bs
DataGridView1.DataSource = bs
TextBox1.DataBindings.Add("text", bs, "nombre")
TextBox2.DataBindings.Add("text", bs, "comentarios")
TextBox3.DataBindings.Add("text", bs, "ruta")
With cnn
If .State = ConnectionState.Open Then
.Close()
End If
.Dispose()
End With
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class