Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'link https://www.facebook.com/groups/programervbnetindonesia/permalink/10157513255228621
- Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
- 'Open File Dialog
- With OFD
- .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
- .Filter = "Text files |*.txt"
- If .ShowDialog = 1 Then
- Using MyReader As New TextFieldParser(.FileName)
- MyReader.TextFieldType = FieldType.Delimited
- MyReader.SetDelimiters(",")
- While Not MyReader.EndOfData
- Try
- 'show all data to listbox
- ListBox1.Items.AddRange(MyReader.ReadFields())
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try
- End While
- End Using
- End If
- End With
- 'insert the data from listbox to db
- Dim constr As String = "Server=DESKTOP-26OLQLK\MSSQLSERVER01;Database=MYDB;" & _
- "User ID=" & "ally" & ";Password=" & "1234567!" & ";" & _
- "Pooling='False';Connection Timeout=30"
- Using ConnImport As New SqlConnection(constr)
- Try
- ConnImport.Open()
- 'fetch the data from listbox items
- For i = 6 To 11
- Using cmd As New SqlCommand("INSERT INTO dbo.Outlet_Data(store_ort_date,store_header_count, " & _
- "store_details_count,store_total_netsales,store_StoreID,store_storename) " & _
- "VALUES (@col1,@col2,@col3,@col4,@col5,@col6)", ConnImport)
- With cmd
- .Parameters.Clear()
- .Parameters.AddWithValue("@col" & i - 5, ListBox1.Items(i))
- .ExecuteNonQuery()
- End With
- End Using
- Next
- ConnImport.Close()
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try
- End Using
- End Sub
Add Comment
Please, Sign In to add comment