에서 개체의 인스턴스로 설정되지 않았습니다 : 내 데이터베이스에있는 파일을 업로드하기 위해 노력하고있어 때개체 참조가 나는 오류를 얻고있다 vb.net
Object reference not set to an instance of an object.
이 나타납니다. 이 여기
내 코드입니다 내 학교에 전달하기 위해 개발하고 프로젝트 (최종 시험)입니다 :Try
OpenFileDialog.Filter = "All files (*.*)|*.*| JPEG FILES(*.jpg)|*.jpg| RAW FILES (*.raw)|*.raw| WORD FILES (*.doc)|*.doc| WORD FILES (*.docx)|*.docx| EXCEL FILES (*.xls)|*.xls| EXCEL Files (*.xlsx)|*.xlsx| PNG Files (*.png)|*.png| GIF FILES (*.gif)|*.gif| PDF FILES (*.pdf)|*.pdf| RAR Files (*.rar)|*.rar| AUTOCAD FILES (*.dwg)|*.dwg| EXE FILES (*.exe)|*.exe| ZIP FILES (*.zip)|*.zip| TXT FILES (*.txt)|*.txt"
OpenFileDialog.FilterIndex = 1
OpenFileDialog.Title = "Open File"
OpenFileDialog.Multiselect = True
obj_openfile = OpenFileDialog
'Show The Dialog
If obj_openfile.ShowDialog = Windows.Forms.DialogResult.OK Then
in_file = obj_openfile.FileName.ToString
Dim fich As String = obj_openfile.SafeFileName
obj_openfile.Dispose()
obj_openfile = Nothing
con.Close()
con.ConnectionString = "Data Source=IZZ;Initial Catalog=regteste;Integrated Security=True"
con.Open()
'Converter to bytesream
Dim fs As FileStream
fs = New FileStream(in_file, FileMode.Open, FileAccess.Read)
Dim docByte As Byte() = New Byte(fs.Length - 1) {}
fs.Read(docByte, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Dim filebyte As Byte() = Nothing
filebyte = System.IO.File.ReadAllBytes(obj_openfile.FileName)
cmd = New SqlCommand("INSERT INTO Filestelefones_pt (Name,Data) VALUES (@Name, @Data)", con)
cmd.Parameters.AddWithValue("@Name", fich)
cmd.Parameters.AddWithValue("@Data", docByte)
cmd.ExecuteNonQuery()
con.Close()
con.Open()
txtabrir.Text = in_file
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
언어 태그를 추가해야합니다. – csmckelvey
어디에서 실패했는지 아십니까? 오류에 대해 더 자세히 설명해 주시겠습니까? –
[NullReferenceException은 무엇이며 어떻게 수정합니까?] 가능한 중복 (http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) 시작, 오류/오류를 확인하는 시도/제거 잡으려고 – Plutonix