title: vb.net import csv to sql server, how to convert the csv string value to sql table int
body: <p>I try to import csv data to sql server database table use vb.net. When I try to convert the csv string value to sql table int, I always fail. I have try to check from google but still don't find a solution.</p>
  
  <p>below is my code:</p>
  
  <pre><code>Dim table As New DataTable()
      Dim parser As New FileIO.TextFieldParser("D:\test_1.csv")
  
      table.Columns.Add("STUDENT_NAME")
      table.Columns.Add("STUDENT_NO")
  
  
      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 TestTable STUDENT_NAME,STUDENT_NO) VALUES (@STUDENT_NAME,@STUDENT_NO)"
      Dim SqlconnectionString As String = "Server=PC_1\TESTDB;Database=test_db;User Id=testuser;Password=testuser;"
      Using connection As New SqlClient.SqlConnection(SqlconnectionString)
          Dim cmd As New SqlClient.SqlCommand(strSql, connection) ' create command objects and add parameters
          With cmd.Parameters
              .Add("@STUDENT_NAME", SqlDbType.VarChar, 15, "STUDENT_NAME")
              .Add("@STUDENT_NO", SqlDbType.Int, "STUDENT_NO")
          End With
  
          Dim adapter As New SqlClient.SqlDataAdapter()
          adapter.InsertCommand = cmd
  
          Dim iRowsInserted As Int32 = adapter.Update(table)
  
      End Using
  </code></pre>
  
  <p>Can anybody help me on this? thanks.</p>