vuhoa
08-08-2007, 18:48
Em đang mò vb.net, xem trong sách và làm đúng như vậy nhưng ko tạo ketnoi toi sql được. Đây là cách em làm
Vào sql tạo 1 database tên test, mật khẩu sa là 123456
Dùng VS 2003 tạo project mới, dblick lên webform gõ code sau
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Khai bao bien chuoi ket noi
Dim cnnStr As String
'Khai bao doi tuong ket noi thuoc SQL
Dim cnn As SQLConnection
'Tao chuoi ket noi toi CSDL SQL server
cnnStr = "server=(local);iud=sa;pwd=123456;database=test"
'Tao doi tuong ket noi CNN
cnn = New SQLConnection
'mo ket noi
cnn.Open()
End Sub
End Class
hết ạ
Xong run thử lỗi tè le
Line 34: cnn = New SQLConnection
Line 35: 'mo ket noi
Line 36: cnn.Open()
Line 37: End Sub
Line 38:
Giúp em với, chắc mua sách khác wa' hixhix
Vào sql tạo 1 database tên test, mật khẩu sa là 123456
Dùng VS 2003 tạo project mới, dblick lên webform gõ code sau
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Khai bao bien chuoi ket noi
Dim cnnStr As String
'Khai bao doi tuong ket noi thuoc SQL
Dim cnn As SQLConnection
'Tao chuoi ket noi toi CSDL SQL server
cnnStr = "server=(local);iud=sa;pwd=123456;database=test"
'Tao doi tuong ket noi CNN
cnn = New SQLConnection
'mo ket noi
cnn.Open()
End Sub
End Class
hết ạ
Xong run thử lỗi tè le
Line 34: cnn = New SQLConnection
Line 35: 'mo ket noi
Line 36: cnn.Open()
Line 37: End Sub
Line 38:
Giúp em với, chắc mua sách khác wa' hixhix