Tienes razón, se resolvió.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúImports System.Data
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cn As New SqlConnection("Server=OMORENO;Database=DBVentas;Integrated Security=True;")
Dim cmd As New SqlCommand("TraerDatos", cn)
Dim dr As SqlDataReader
cn.Open()
Try
cmd.CommandType = CommandType.StoredProcedure
dr = cmd.ExecuteReader()
Dim strStreamW As Stream
Dim strStreamWriter As StreamWriter
dr.Read()
Dim FilePath As String = "C:\Users\Oscar Moreno\Desktop\prueba.txt"
strStreamW = File.OpenWrite(FilePath)
strStreamWriter = New StreamWriter(strStreamW, System.Text.Encoding.UTF8)
'AGREGANDO LA INFORMACION
While dr.Read()
strStreamWriter.WriteLine("|" & CStr(dr("DNIUsuario")) & "|" & campo1 & "||" & (CStr(dr("ApellidoPaterno"))) & "|" & (CStr(dr("ApellidoMaterno"))) & "|" & (CStr(dr("FechaNacimimento"))) & "|")
End While
strStreamWriter.Close()
dr.Close()
cn.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
cn.Close()
End Try
End Sub
End Class
Imports System.Data.SqlClient
Public Class Form1
Dim dt As New DataSet
Dim dt2 As New SqlDataAdapter
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim servidor As String
Dim basededatos As String
servidor = "OMORENO"
basededatos = "DBVentas"
conexion(servidor, basededatos)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim datillos As SqlDataAdapter
Dim sql As String
Dim dt As New DataSet
sql = "SELECT * FROM Usuario WHERE Nombre='" & TextBox1.Text & & "' AND FechaNacimimento BETWEEN '20131201' AND '20131215'"
datillos = New SqlDataAdapter(sql, miconexion)
datillos.Fill(dt)
DataGridView1.DataSource = dt.Tables(0)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SaveIt.InitialDirectory = "C:\TXT"
SaveIt.FileName = "temp.txt"
SaveIt.Filter = "Archivos de Texto (*.txt)| *.txt"
SaveIt.ShowDialog()
'Generando el archivo
Dim w As New IO.StreamWriter(SaveIt.FileName)
' AGREGANDO LAS COLUMNAS
Dim col As String = ""
' AGREGANDO LAS FILAS
Dim row As String = ""
Dim i As Integer = 0
For Each r As DataGridViewRow In DataGridView1.Rows
For Each c As DataGridViewColumn In DataGridView1.Columns
'VARIABLE QUE ALMACENA TODOS LOS CAMPOS DE LA TABLA
row = row & Convert.ToString(r.Cells(c.HeaderText).Value)
Next
If i < DataGridView1.Rows.Count - 1 Then row &= Environment.NewLine
Next
'AGREGANDO LA INFORMACION
w.WriteLine(row)
w.Close()
End Sub
End Class