web 2.0

ASP.NET(vb.net) & SQL Server Connect to Database

ASP.NET(vb.net) & SQL Server Connect to Database - This how to learn use ASP.NET web application connect to SQL Server database and using System.Data.SqlClient

ShotDev Focus:
- ASP.NET(vb.net) & SQL Server Connect to Database

Example

AspNetSQLServerConnect.aspx

  1. <%@ Import Namespace="System.Data"%>  
  2. <%@ Import Namespace="System.Data.SqlClient"%>  
  3. <%@ Page Language="VB" %>  
  4. <script runat="server">  
  5.   
  6. Dim objConn As SqlConnection  
  7. Dim objCmd As SqlCommand  
  8.   
  9. Sub Page_Load(sender As Object, e As EventArgs)  
  10. Dim strConnString As String  
  11. strConnString = "Server=localhost;Uid=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"  
  12. objConn = New SqlConnection(strConnString)  
  13. objConn.Open()  
  14.   
  15. If objConn.State = ConnectionState.Open Then  
  16. Me.lblText.Text = "SQL Server Connected"  
  17. Else  
  18. Me.lblText.Text = "SQL Server Connect Failed"  
  19. End IF  
  20. End Sub  
  21.   
  22. Sub Page_UnLoad()  
  23. objConn.Close()  
  24. objConn = Nothing  
  25. End Sub  
  26.   
  27. </script>  
  28. <html>  
  29. <head>  
  30. <title>ShotDev.Com Tutorial</title>  
  31. </head>  
  32. <body>  
  33. <form id="form1" runat="server">  
  34. <asp:Label id="lblText" runat="server"></asp:Label>  
  35. </form>  
  36. </body>  
  37. </html>  

Screenshot

ASP.NET(vb.net) & SQL Server Connect to Database
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

One Response to “ASP.NET(vb.net) & SQL Server Connect to Database”

  1. 3oriented…

Leave a Reply

You must be logged in to post a comment.