ODBC + Textbox + Insert Record 使用方法

 
ODBC + Textbox + Insert Record 使用方法
 

   Form1.vb
 
   Private Sub ODBCInsertData()
 
      Dim ConnString As String = _
      "Driver={SQL Native Client};" & _
      "Server=VECTUS\SQLEXPRESS;" & _
      "Database=Soccer;Trusted_Connection=yes;"
 
      Dim ODBCConnection1 As New Odbc.OdbcConnection(ConnString)
 
      Try
 
         ODBCConnection1.Open()
 
         Dim SqlString1 As String = "INSERT INTO dbo.Team (Team_ID, Team_Name, League_ID) " & _
         "VALUES('" & TextBox1.Text.ToString.Trim & _
         "', '" & TextBox2.Text.ToString.Trim & _
         "', '" & TextBox3.Text.ToString.Trim & "')"
 
         Dim cmd1 As OdbcCommand = New OdbcCommand(SqlString1, ODBCConnection1)
 
         cmd1.ExecuteNonQuery()
 
         cmd1.Dispose()
         ODBCConnection1.Dispose()
 
      Catch ex As Exception
 
         MsgBox("Cannot open connection ! ")
 
      End Try
 
   End Sub