How to solve a form hangs problem during on inserting data to the database?
Can someone help me with the following codes?
Thank you!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim table As New DataTable()
table.Columns.Add("xxx")
table.Columns.Add("xxx")
table.Columns.Add("xxx")
table.Columns.Add("xxx")
Dim parser As New FileIO.TextFieldParser(OpenFileDialog1.FileName.ToString())
parser.Delimiters = New String() {","}
parser.HasFieldsEnclosedInQuotes = True
parser.TrimWhiteSpace = True
parser.ReadLine()
Do Until parser.EndOfData = True
table.Rows.Add(parser.ReadFields())
Loop
Dim strSql As String = "INSERT INTO Report (xxx,xxx......) VALUES (@xxx,@xxx,@xxx.......)" & "Update Report Set xxx= UPPER(xxx)"
Dim SqlconnectionString As String = "Data Source=xxxxx\SQLEXPRESS;Initial Catalog=master;User Id=xxxx;Password=xxxxx;"
Using connection As New SqlClient.SqlConnection(SqlconnectionString)
Try
Dim cmd As New SqlClient.SqlCommand(strSql, connection)
With cmd.Parameters
.Add("@xxx", SqlDbType.VarChar, 50, "xxx")
.Add("@xxx", SqlDbType.VarChar, 50, "xxx")
.Add("@xxx", SqlDbType.VarChar, 50, "xxx")
.Add("@xxx", SqlDbType.VarChar, 50, "xxx")
End With
Dim adapter As New SqlClient.SqlDataAdapter()
adapter.InsertCommand = cmd
Dim iRowsInserted As Int32 = _
adapter.Update(table)
Catch eSql As System.Data.SqlClient.SqlException
MessageBox.Show(eSql.ToString)
End Try
MsgBox("Successfull Insert " & (OpenFileDialog1.FileName.ToString()))
End Using
Me.Close()
End Sub

New Topic/Question
Reply




MultiQuote



|