2012年3月31日 星期六

SqlParameters


  1. Dim Sql_DataSource As New SqlDataSource
  2. Sql_DataSource.ConnectionString="DataSource=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|DB.mdf;Integrated Security=True;User Instance=True" '設定資料庫
  3. 'Account是參數名稱,也就是最下方的SelectCommand後面的@Account
  4. Sql_DataSource.SelectParameters.Add("Account", Account.Text)
  5. Sql_DataSource.SelectParameters.Add("Password", Password.Text)
  6. Sql_DataSource.SelectCommand = "select * from Member where Account=@Account and Password=@Password"

  7. Dim dv As DataView
  8. dv = CType(Sql_DataSource.Select(DataSourceSelectArguments.Empty), DataView)
  9. If dv.Table.Rows.Count - 1 = -1 Then
  10. '無資料
  11. Else
  12. '有資料
  13. End If
  14. Sql_DataSource.Dispose()