Showing posts with label ASP.NET with SQL Server 2005 DataBase. Show all posts
Showing posts with label ASP.NET with SQL Server 2005 DataBase. Show all posts

ASP.NET with SQL Server 2005 DataBase

CREATE DATABASE AND TABLE



 

ASP.NET with Database connection
VB.NET



Source code

Imports System
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myConnection As System.Data.SqlClient.SqlConnection
        Dim myCommand As System.Data.SqlClient.SqlCommand
        Dim strSQL As String
        myConnection = New SqlConnection("Data Source=USER-PC;Initial Catalog=master;User ID=sa;Password=system") 'master is database name,User is  hostname

        myConnection.Open() 'Open the connection
        strSQL = "SELECT * FROM log where id=" + TextBox1.Text  'log is tablename,id is field
        myCommand = New SqlCommand(strSQL, myConnection)
        Dim re As SqlDataReader = myCommand.ExecuteReader()
        While re.Read
            TextBox2.Text = re.GetString(1).ToString’Read rows
        End While
    End Sub
End Class



Run the website




Your IP Address is:

Browser: