이 코드의 문제점을 알려주십시오.Insert에 대한 ExecuteNonQuery()
표에 삽입하려면 DataAdapter
을 사용해야합니까?
서버 탐색기에서 테스트했기 때문에 connectionString
은 괜찮습니다.
Dim mydao As New Connection
Dim connectionString As String = mydao.GetConnectionString()
Dim connection As New SqlConnection(connectionString)
Dim cmd As New SqlCommand
Public Function add(ByVal area As String, ByVal user As String) As Integer
cmd.CommandText = "INSERT into Area (Area, user) VALUES ('" + area + "','" + user + "')"
Try
connection.Open()
Dim cant As Integer = cmd.ExecuteNonQuery()'it throws exception here
connection.Close()
Return cant
Catch ex As Exception
Console.WriteLine(ex.Message)
Return 0
End Try
End Function
은 위의 코드는 바로 뒤에 ExecuteNonQuery()
왜 안 들려요 그림을 실패합니다.
TARGET 필드 (SQL 서버 2008) :
이AREA varchar(100) NOT NULL ,
USER varchar(100) NOT NULL
내가받을 예외는 다음과 같습니다 Connection property has not initialized
이
오류 메시지 수행 방법 너는받을거야? – Alex
연결을 여는 중이지만 해당 연결에 명령의 연결 속성을 설정하지 않은 것으로 보입니다. – kwwallpe
연결 속성이 초기화되지 않았습니다. – phalanx