View Full Version : help me in connect database
ở nhà tui viết một chương trình đọc data ra data reader.. nhưng mà khi chạy thì nó thông báo ở dòng sau:
dim myqslcommand as new sqlclient.sqlcommand(myconnecstring,myconnect)
myqslcommand.connection.open()
và hắn hiện lên thông báo lỗi sau
An handked exception of type 'System.data.sqlclient.sqlexception' occured in system.data.dll
additional information : system error
ở nhà tui mới cài win 2003 và cài bộ sv.net 2003 luôn nên không thể có chuyện lỗi hệ thống .. ai bít thì chrir giùm nhé
rainOfSadness
03-07-2003, 11:06
myqslcommand.connection.open()
đã truyền connection string vào rồi thì bỏ dòng này đi. object SqlCommmand sẽ tự lo phần connection.
tôi đã thử bỏ đi thì hắn lại báo lỗi các dòng về sau và hiện lên thông báo mới ... hic .. tui đang ở dv nên ko thể đưa cái thông báo đó lên đây .. để tui về chép từ đầu đến cuôi cho các bạn coi
tôi đã thử bỏ đi thì hắn lại báo lỗi các dòng về sau và hiện lên thông báo mới ... hic .. tui đang ở dv nên ko thể đưa cái thông báo đó lên đây .. để tui về chép từ đầu đến cuôi cho các bạn coi
Dim myconnection As New sqlclient.SqlConnection
myConnection.connectionString = "data source=professional;persist security info=true;initial catalog=NorthwindSQL"
Dim mySqlString As String ="SELECT * FROM products"
dim mySelectCommand As New SqlClient.SqlCommand(mysqlstring,myconnection)
mySelectCommand.connection.open()
dim myReader As SqlCliect.SqlDataReader = mySelectCommand.ExecuteReader
nếu bỏ phần đánh dấu đi thì nó sẽ báo lỗi sau:
Additional inỏmation : ExecuteReader requires an open and Availble connection. The connection 's curent state 's closed.
Như vậy là cái câu lệnh đó hổng thể bỏ được
rainOfSadness
03-07-2003, 16:42
dim myqslcommand as new sqlclient.sqlcommand(myconnecstring,myconnect)
cú pháp u ghi ra ở bài post đầu tiên là thế, nên tôi nghĩ nếu truyền vào ConnectionString thì SqlCommand sẽ lo việc tạo connection. Trong trường hợp cú pháp như bài post thứ 2 của u :
dim mySelectCommand As New SqlClient.SqlCommand(mysqlstring,myconnection)
thì parameter truyền vào là một Connection. Dĩ nhiên u phải open connection trước khi sử dụng với DataReader. Thử thế này xem :
Dim myconnection As New sqlclient.SqlConnection
myConnection.connectionString = "data source=professional;persist security info=true;initial catalog=NorthwindSQL"
myConnection.Open()
Dim mySqlString As String ="SELECT * FROM products"
dim mySelectCommand As New SqlClient.SqlCommand(mysqlstring,myconnection)
mySelectCommand.connection.open() ' phang-teo this
dim myReader As SqlCliect.SqlDataReader = mySelectCommand.ExecuteReader
rainOfSadness
03-07-2003, 16:46
nhớ bỏ dòng màu đỏ đi nha. 1 2 3 4 5 6 7 8 9 0 (cho đủ 50 ký tự)
ok tui sẽ thử cám ơn u nhiều lắm nếu không được thì lên hỏi tiếp
xuandt85
12-02-2009, 00:18
bạn có thể vào đây để tham khảo nhé :
http://www.smtat.com/index.php?topic=9.0
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.