PDA

View Full Version : có lỗi này mà tìm hoài không ra ( asp net sai viual208 , database sql2008)



haiboss
25-05-2009, 15:58
đoạn code như sau viết trên destop chay được nhưng web báo lỗi:
Command = New SqlCommand()
Command.Connection = cnn
Command.CommandText = SQL
Command.CommandType = CommandType.StoredProcedure
If TryToConnect() = True Then
DataAdapter = New SqlDataAdapter
DataAdapter.SelectCommand = Command
ds = New DataSet
DataAdapter.Fill(ds, "test") <-- day nè
If ds.Tables(0).Rows.Count > 0 Then
Return ds.Tables(0).Rows.Count
Else
Return SQL
End If 'ds
End If



error : SelectCommand.Connection property has not been initialized.
chuoi connectstring :
Data Source=10.56.4.34,5050;Network Library=DBMSSOCN;Initial Catalog=Northwind;User ID=sa;Password="";
chuổi connectstring nằm trong file web.config
<appSettings>
<add key="conn" value="Data Source=10.56.4.34,5050;Network Library=DBMSSOCN;Initial Catalog=Northwind;User ID=sa;Password="";"/>
</appSettings>
<connectionStrings>
<add name="conn" connectionString="Data Source=10.56.4.34,5050;Network Library=DBMSSOCN;Initial Catalog=Northwind;User ID=sa;Password="";" providerName="System.Data.SqlClient"/>
</connectionStrings>
có anh chị nào bị lổi này chỉ e khắc phục.e xin Cảm ơn

phamvanhung8590
23-06-2011, 08:34
Viết code ko có sqlconnectstring thì chạy bằng niềm tin ah. viết lại chuỗi kết nối đi bạn. rồi dùng phương thức mở chuỗi kết nối thì mới sử dụng được .

megaownage
23-06-2011, 09:44
Trong code trên, biến cnn của bạn chưa có trị