works with: ASP.net using VB.net connection to MS SQL Server
What I'm trying to do is take the result of the SQL select query and put it in a string variable so that it can be used in things like a text box or shortcut. the code doesn't work yet ...
Imports System.Data.SqlClient
Partial class dev_Default Inherits System.Web.UI.Page
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
Dim cnPodaci As New SqlConnection
cnPodaci.ConnectionString = "Data Source=<server>;Initial Catalog=<DB>;User ID=<UserName>;Password=<Password>"
cnPodaci.Open()
Dim cm As New SqlCommand
cm.CommandText = "SELECT * FROM tbl1"
cm.Connection = cnPodaci
Dim dr As SqlDataReader
dr = cm.ExecuteReader
TextBox1.Text = dr.GetString(0)
cnPodaci.Close()
End Sub
Final class
Tommy
source
share