Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 30th, 2012  |  syntax: VB.NET  |  size: 0.52 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Dim conn as SqlConnection = new SqlConnection("Data Source=localhost;Initial Catalog=database;User ID=uid;Password=pass")
  2. conn.Open()
  3.  
  4. ' assuming a textbox with id txtUserId exists on the aspx page
  5. Dim userId as String = txtUserId.Text
  6. Dim sql as String = "SELECT name, password FROM users WHERE id=@userid"
  7.  
  8. Dim cmd as SqlCommand = new SqlCommand()
  9. cmd.Connection = conn
  10. cmd.CommandType = CommandType.Text
  11. cmd.CommendText = sql
  12. cmd.Parameters.AddWithValue("userid", userId);
  13.  
  14. Dim dr as SqlDataReader = cmd.ExecuteReader()