SQLDataAdapter + SQLParemeter + DataGridView 使用方法 (1)

 

   SQLDataAdapter + SQLParemeter + DataGridView 使用方法 (1)
 
   Private Sub GridView_Get()
 
      Dim connectionString1 As String = "Data Source=.\SqlExpress; Initial Catalog=Soccer; Integrated Security=SSPI"
      Dim con1 As SqlConnection = New SqlConnection(connectionString1)
      con1.Open()
 
      Dim SqlString1 As String = "SELECT Player_ID, Player_Name FROM dbo.Player WHERE Player_ID < @MAXSIZE"
 
      Dim Adapter As New SqlDataAdapter
      Adapter.SelectCommand = New SqlCommand(SqlString1.ToString(), con1)
      Adapter.SelectCommand.Parameters.AddWithValue("@MAXSIZE", "10")
 
      Dim ds As New DataSet
      Adapter.Fill(ds)
 
      DataGridView1.DataSource = ds.Tables(0).DefaultView
 
      ds.Dispose()
      con1.Dispose()
 
   End Sub