SHARE
TWEET

VB ADO.NET KDU

a guest Oct 21st, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.SqlClient
  2. Public Class RecipeForm
  3.     Dim conn As SqlConnection
  4.     Dim allRecipesCmd As SqlCommand
  5.  
  6.     Private Sub RecipeForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  7.         Dim connStr = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Nutrition.mdf;Integrated Security=True"
  8.         conn = New SqlConnection(connStr)
  9.         conn.Open()
  10.     End Sub
  11.  
  12.  
  13.  
  14.     Private Sub RecipeForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
  15.         conn.Close()
  16.     End Sub
  17.  
  18.     Private Sub AllButton_Click(sender As Object, e As EventArgs) Handles AllButton.Click
  19.         allRecipesCmd = New SqlCommand("SELECT name FROM Recipe ORDER BY name", conn)
  20.         Dim reader As SqlDataReader = allRecipesCmd.ExecuteReader()
  21.         Do While reader.Read()
  22.             RecipeListBox.Items.Add(reader.GetString(0))
  23.         Loop
  24.     End Sub
  25. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top