Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Dim sqlcon As SqlConnection
Dim ds As DataSet
Dim da As SqlDataAdapter
Dim myFileDlog As New OpenFileDialog()
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Dim myFileDlog As New OpenFileDialog()
'look for files in the c drive
myFileDlog.InitialDirectory = "c:\"
'specifies what type of data files to look for
myFileDlog.Filter = "All Files (*.*)|*.*"
'specifies which data type is focused on start up
myFileDlog.FilterIndex = 2
'Gets or sets a value indicating whether the dialog box restores the current directory before closing.
myFileDlog.RestoreDirectory = True
'seperates message outputs for files found or not found
If myFileDlog.ShowDialog() = _
DialogResult.OK Then
End If
'Adds the file directory to the text box
txtFileDirectory.Text = myFileDlog.FileName
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(myFileDlog.FileName)
End Sub
Private Sub txtFileDirectory_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFileDirectory.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub showData()
ds = New DataSet
da = New SqlDataAdapter("SELECT * FROM Foreign_visitor_logs", sqlcon)
da.Fill(ds, "Foreign_visitor_logs")
'DataGridView1.DataSource = ds.Tables("Foreign_visitor_logs")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
sqlcon = New SqlConnection("Server=.;Database=visitorTRU;User Id=sa;Password=1234")
sqlcon.Open()
MsgBox("Connected")
Catch ex As Exception
MsgBox("Error")
End Try
Call showData()
Dim filename As String
filename = txtFileDirectory.Text
Dim iofile As New StreamReader(filename)
Dim ioline As String
Dim Fl_ID, Fl_Date, Fl_Time, Fl_Description, Fl_IPAddress
ioline = iofile.ReadLine
While Not ioline = ""
Dim mysplit = Split(ioline, ",")
Fl_ID = mysplit(0)
Fl_Date = mysplit(1)
Fl_Time = mysplit(2)
Fl_Description = mysplit(3)
Fl_IPAddress = mysplit(4)
Dim inscmd As New SqlCommand
inscmd.CommandText = ("insert into Foreign_visitor_logs values('" + mysplit(0) + "')")
Print(inscmd.CommandText)
inscmd.Connection = sqlcon
inscmd.ExecuteNonQuery()
inscmd.Parameters.Clear()
MsgBox("Your booking has been successfully")
End While
End Sub
End Class
Tag : .NET, Ms SQL Server 2008, VS 2010 (.NET 4.x)
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Dim sqlcon As SqlConnection
Dim ds As DataSet
Dim da As SqlDataAdapter
Dim myFileDlog As New OpenFileDialog()
Public Sub connection()
Try
sqlcon = New SqlConnection("Server=.;Database=visitorTRU;User Id=sa;Password=1234")
sqlcon.Open()
MsgBox("Connected")
Catch ex As Exception
MsgBox("Error")
End Try
End Sub
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Dim myFileDlog As New OpenFileDialog()
'look for files in the c drive
myFileDlog.InitialDirectory = "c:\"
'specifies what type of data files to look for
myFileDlog.Filter = "All Files (*.*)|*.*"
'specifies which data type is focused on start up
myFileDlog.FilterIndex = 2
'Gets or sets a value indicating whether the dialog box restores the current directory before closing.
myFileDlog.RestoreDirectory = True
'seperates message outputs for files found or not found
If myFileDlog.ShowDialog() = _
DialogResult.OK Then
End If
'Adds the file directory to the text box
txtFileDirectory.Text = myFileDlog.FileName
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(myFileDlog.FileName)
End Sub
Private Sub txtFileDirectory_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFileDirectory.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub showData()
ds = New DataSet
da = New SqlDataAdapter("SELECT * FROM Foreign_visitor_logs", sqlcon)
da.Fill(ds, "Foreign_visitor_logs")
DataGridView1.DataSource = ds.Tables("Foreign_visitor_logs")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
sqlcon = New SqlConnection("Server=.;Database=visitorTRU;User Id=sa;Password=1234")
sqlcon.Open()
MsgBox("Connected")
Catch ex As Exception
MsgBox("Error")
End Try
Dim filename As String
filename = txtFileDirectory.Text
Dim iofile As New StreamReader(filename)
Dim ioline As String
Dim Fl_ID, Fl_Date, Fl_Time, Fl_Description, Fl_IPAddress, Fl_HostName, Fl_MacAddress, Fl_Username, Fl_TransactionID, Fl_QResult, Fl_Probationtime, Fl_CorrelationID, Fl_Dhcid As String
' ioline = iofile.ReadLine
'Dim LineRichtext As Integer = TextBox1.Lines.Length
'iofile.ReadLine()
While iofile.Peek() <> -1
ioline = iofile.ReadLine
Dim mysplit = Split(ioline, ",")
Fl_ID = mysplit(0)
Fl_Date = mysplit(1)
Fl_Time = mysplit(2)
Fl_Description = mysplit(3)
Fl_IPAddress = mysplit(4)
Fl_HostName = mysplit(5)
Fl_MacAddress = mysplit(6)
Fl_Username = mysplit(7)
Fl_TransactionID = mysplit(8)
Fl_QResult = mysplit(9)
Fl_Probationtime = mysplit(10)
Fl_CorrelationID = mysplit(11)
Fl_Dhcid = mysplit(12)
Dim str As String
str = "insert into Foreign_visitor_logs (Fl_ID, Fl_Date, Fl_Time, Fl_Description, Fl_IPAddress, Fl_HostName, Fl_MacAddress, Fl_Username, Fl_TransactionID, Fl_QResult, Fl_Probationtime, Fl_CorrelationID, Fl_Dhcid) values('" + mysplit(0) + "','" + mysplit(1) + "','" + mysplit(2) + "','" + mysplit(3) + "','" + mysplit(4) + "','" + mysplit(5) + "','" + mysplit(6) + "','" + mysplit(7) + "','" + mysplit(8) + "','" + mysplit(9) + "','" + mysplit(10) + "','" + mysplit(11) + "','" + mysplit(12) + "')"
Dim myCommand As SqlCommand = New SqlCommand(str, sqlcon)
Try
sqlcon.Open()
myCommand.ExecuteNonQuery()
myCommand.Parameters.Clear()
Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
If (sqlcon.State = ConnectionState.Open) Then
sqlcon.Close()
End If
End Try
End While
MessageBox.Show("successfully")
Call showData()
End Sub
End Class