vb.net 2010의 새로운 기능으로, 데이터를 mysql 데이터베이스로 업데이트하는 중에 예외가 발생했습니다. 무슨 일이 일어나고 있는지 모르겠지만, 문제를 해결할 수 없습니다.문자열 "SystemNullReferenceException : O"에서 유형 '정수'로 변환이 올바르지 않습니다.
Private sub updateData()
Dim path As String = "IMAGES/"
Dim reg As String = 1
dbcon.Close() ' This will close any open connection
con = "server=localhost; uid=root;pwd=;database=myDatabase;"
Try
dbcon.ConnectionString = con
dbcon.Open()
sql = "update t_table1 set data1='" & data1.Text & "',data2='" & data2.Text & "',"',reg='" & reg & "' where id='" & id.text & "';"
dbcom = New MySqlCommand(sql, dbcon)
dbcom.ExecuteNonQuery()
Try
If Not Directory.Exists(path) Then
'This will create a directory "IMAGE"
Dim di As DirectoryInfo = Directory.CreateDirectory(path)
End If
If Not PictureBox1.Image Is Nothing Then
'If the picturebox contain an image then it will save into "IMAGE"directory
PicCopy.Save(String.Concat(path, id.Text, ".png"))
Else
End If
Catch ex As Exception
MsgBox("The process failed: ", ex.ToString())
End Try
MsgBox("Records Successfully Update!", MsgBoxStyle.Information)
dbcon.Close()
Catch ex As Exception
MsgBox("Unable to update data. Error is " & ex.Message)
dbcon.Close()
Exit Sub
End Try
End Sub
내가 뭘하려고 오전입니다 :이 열려있는
- 연결을 닫습니다 여기 내 코드입니다 'data1'및 'data2'여기서 id = "id.text texbox의 값"
- "IMAGE"디렉토리가 존재하는지 확인하십시오. 작성하지 않은 경우 확인하십시오.
- 확인하십시오. 포함 된 다음 "id.text의 texbox"의 이름으로와 ".png를"
- 수행 연결
- 을 닫으의 파일 확장자 이미지 이토 "IMAGE"디렉토리를 저장하는 경우 picturebox2는 이미지를 포함
하지만이 기능 내 데이터를 호출 할 때마다 업데이트를했다하지만 나에게 그 말을 예외 오류 제공 : 데이터를 업데이트 할 수
수 없음을. 오류는 변환 양식 문자열 "SystemNullReferenceException : O"에서 '정수'유형이 유효하지 않습니다.
sql 쿼리는 ** 쓸모가 없습니다 **. 읽기 : [매개 변수화 된 SQL 쿼리는 어떻게 작성합니까? 왜해야합니까?] (http://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i) 및 this : [매개 변수화 된 SQL을 제공하거나 나에게 죽음을주십시오] (http://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/). –