hola con una duda en vb.net

#1
Private Sub CreateGraph_DataSource(z1 As ZedGraphControl)
Dim myPane As GraphPane = z1.GraphPane

' Set the titles
myPane.Title.Text = "DataSourcePointList Test"
myPane.XAxis.Title.Text = "Date"
myPane.YAxis.Title.Text = "Freight Charges ($US)"

(-----> ' Create a new DataSourcePointList to handle the database connection
Dim dspl As New DataSourcePointList()
' Create a TableAdapter instance to access the database
Dim adapter As New NorthwindDataSetTableAdapters.OrdersTableAdapter()
' Create a DataTable and fill it with data from the database
Dim table As NorthwindDataSet.OrdersDataTable = adapter.GetData()<---------)

' Specify the table as the data source
dspl.DataSource = table
' The X data will come from the "OrderDate" column
dspl.XDataMember = "OrderDate"
' The Y data will come from the "Freight" column
dspl.YDataMember = "Freight"
' The Z data are not used
dspl.ZDataMember = Nothing
' The Tag data will come from the "ShipName" column
' (note that this will just set PointPair.Tag = ShipName)
dspl.TagDataMember = "ShipName"




lo que esta encerrado es para enlazar un base de datos en access

como la puedo cambiar para un base de datos normal (mysql , phpmyadmin )


por favor
:vientos:
:cute:
 

Sherbec

Bovino maduro
#2
Hola que tal, eso no es ninguna conexion a base de datos... solamente son variables que van a permitir la "visualizacion" de datos en una tabla. ¿Que es lo que necesitas hacer para poderte ayudar? Saludos
 

ToroEon

Bovino Milenario
#3
Cómo dice el compa bakuno de arriba, sólo son variables pero te dejo un ejemplo y ya lo adaptas al tuyo, Ok?

Option Explicit On
Option Strict On
Option Compare Text

'Una vez añadida la referencia a MySQLDriverCS.dll
'añadimos la clásula Imports correspondiente
Imports MySQLDriverCS

Public Class Form1
Inherits System.Windows.Forms.Form

#Region "Código generado por el Diseñador[...]"

Private
Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'La variable bConexionExitosa nos permitirá finalizar el
'programa si la conexión falla
Dim bConexionExitosa As Boolean = True

'Creamos un objeto de tipo Connection y configuramos los parámetros de la conexión
Dim DBCon As MySQLConnection
'Los parámetros de la sobrecarga con más parámetros son:
'1. Dirección IP o nombre de la máquina con el servidor de MySQLS
'2. Nombre de la base de datos
'3. Nombre de usuario con acceso a la base de datos señalada anteriormente
'4. Contraseña para el nombre de usuario citado
'5. Puerto por el que se acede al servidor. Típicamente 3306
DBCon = New MySQLConnection(New MySQLConnectionString("192.168.0.1", "net", "root", "xxxxxxxxxx", 3306).AsString)

Try
'Abrimos la conexión y comprobamos que no hay error
DBCon.Open()
Catch ex As MySQLException
'Si hubiese error en la conexión mostramos el texto de la descripción
MsgBox(ex.Message.ToString)
bConexionExitosa = False
End Try

'Si no hay ningún problema continuamos
If bConexionExitosa Then

'EJEMPLO 1: Uso de la consulta predefinida MySQLSelectCommand, que ejecuta
'una consulta SELECT

'Definimos dos arrays de String, f y t, que contendrán, respectivamente, los
'campos (fields) que la consulta devolverá y la tablas sobre las que se ejecutará.
'Las cláusulas WHERE y ORDER BY no las utilizaremos, de ahí los Nothing
Dim f() As String = {"id", "nombre"}
Dim t() As String = {"prueba"}

'Ejecutamos la consulta mediante el comando MySQLSelectCommand
Dim dt As DataTable = New MySQLSelectCommand(DBCon, f, t, Nothing, Nothing, Nothing).Table
'Si la consulta produjo algún resultado los mostraremos mediante un MsgBox
'La clase DataTable contiene una colección accesible mediante .Rows
'en la que se almacenan los resultados como variables DataRow
If (dt.Rows.Count <> 0) Then
'Creamos una variable DataRow para contener los elementos resultantes
Dim drow As DataRow
'Al tratarse de una colección podemos recorrerla mediante For Each...In
For Each drow In dt.Rows
'DataRow tiene un método por defecto llamado .Item(...) que permite
'devolver el elemento indicado por el índice o el nombre de la columna
MsgBox(drow("nombre"))
Next
End If


'EJEMPLO 2: Uso de una consulta genérica en SQL utilizando el método
'MySQLCommand del Namespace MySQLDriverCS

'Instanciamos un objeto de la clase MySQLCommand utilizando el constructor por defecto
Dim sql As MySQLCommand = New MySQLCommand
'Establecemos el tipo Connection que usará para realizar la petición
sql.Connection = DBCon
'Escribimos la consulta que deseamos en T-SQL. Nuestro ejemplo buscará todos
'los nombres cuya segunda letra sea 'a' y penúltima 'e'
sql.CommandText = "SELECT * FROM `prueba` WHERE `nombre` LIKE '_a%e_';"
'Como el comando no es almacenado ni vinculado a un tabla elegimos el tipo .Text
sql.CommandType = CommandType.Text

'Creamos un lector de datos (IDataReader) y lo inicializamos
'con el lector del objeto MySQLCommand
Dim dr As System.Data.IDataReader
dr = sql.ExecuteReader()
'Mientras haya datos para leer los mostramos
While dr.Read()
'Al igual de los objetos DataRow, la clase IDataReader también tiene
'un método por defecto .Item que funciona exactamente igual
MsgBox(dr("nombre"))
End While

'Cerramos la conexión con el servidor
DBCon.Close()

End If
End Sub
End Class

Espero y te sirva!!!:metal:

Fuente: http://www.elguille.info/colabora/puntonet/versae_mysqlnet.htm
 
#4
???¿¿¿

aaa que rara forma de pregramar. pero mi hermnao eso no es una coneccion a una base de datos.

mmm deves de usar la sentencia Open de ADOC
que utilisa el ACDB del OLDB
con Coneccion.open
pero imbestiga el modo Open de ADOC
 
#5
ESCRIBE LA LIBRERIA CON IMPORTS SYSTEM.MYSQL
REALIZAS LA CONEXION DATA SOURCE"TUSERVIDOR" ; DATA BASE"tU BASE"; INTEGRATED SECURITY=TRUE

Y MANDAS A LLAMAR UN GRIDVIEW LO CONCATENAS CON UN TEXT O LO QUE GUSTES
 
#6
pues una forma fasil, y espero pueda lludarte es la siguiente, para la coneccion con la vase de datos dises y si no me equiboco.

Public conexion As ADODB.Connection
Public tabla As ADODB.Recordset

Private Sub Cmdcrear_Click() // este boton es para crear la vase de datos, o guardar los datos
Set tabla = New ADODB.Recordset
Set tabla = conexion.Execute("select * from usuarios where usuario='" & Txtusu.Text & "'", , adCmdText)
If tabla.EOF Then
If (Txtpas.Text = Txtpas2.Text) Then
If Opt1.Value Then
nive = 1
End If
If (Opt2.Value) Then
nive = 2
End If
conexion.Execute "insert into usuarios values('" & Txtusu.Text & "','" & Txtpas.Text & "'," & nive & ")", , adCmdText
MsgBox "SE HA CREADO EL NUEVO USUARIO", vbInformation, "aviso"
Txtpas.Text = ""
Txtpas2.Text = ""
Opt1.Value = False
Opt2.Value = False
Txtusu.Text = ""
Txtusu.SetFocus
Else
MsgBox "VUELVE A CONFIRMAR CONTRASEÑA", vbExclamation, "aviso"
Txtpas2.Text = ""
Txtpas2.SetFocus
End If
Else
MsgBox "NO SE PUEDE CREAR USUARIO, YA EXISTE", vbCritical, "aviso"
Txtusu.Text = ""
Txtusu.SetFocus
End If

End Sub

Private Sub Form_Activate()
On Error GoTo bandera

'crea la conexion a la base de datos

Set conexion = New ADODB.Connection
conexion.ConnectionString = "provider=microsoft.ACE.OLEDB.12.0;Data source=:eek:\Mis Documentos\puebla\Biblioteca.accdb;persist security info=false"
conexion.Open
Exit Sub
bandera:
MsgBox Err.Description, vbCritical, "AVISO"
Unload Me
End Sub


aver si te sirve ijo, saludos, ya estoy muy viejo para esto...
 
Arriba