0
我得到一個錯誤,如何解決「ExecuteNonQuery:CommandText屬性尚未初始化?」錯誤?
「的ExecuteNonQuery:CommandText屬性尚未初始化」
請幫助!我一直在執行這個代碼來保存我的其他表單中的數據與我們的任何錯誤,但是當我嘗試使用這個圖像保存它給我這個錯誤。
Sub Save_Employee()
Dim conn As New SqlConnection(ConnectionString)
Dim comm As SqlCommand = New SqlCommand()
comm.Connection = conn
conn.Open()
Dim str As String = "INSERT INTO Employee_Tbl VALUES (@RegNo,@FullName,@Country,@Occupation,@WorkSite,@DOB,@Photo,@Remarks,@Status)"
comm.Parameters.AddWithValue("@RegNo", RegNo_TextBox.Text)
comm.Parameters.AddWithValue("@FullName", FullName_TextBox.Text)
comm.Parameters.AddWithValue("@Country", Country_ComboBox.Text)
comm.Parameters.AddWithValue("@Occupation", Occupation_ComboBox.Text)
comm.Parameters.AddWithValue("@WorkSite", WorkSite_TextBox.Text)
comm.Parameters.AddWithValue("@DOB", DOB_DateTimePicker.Text)
Try
Dim ms As New System.IO.MemoryStream
Dim bmpImage As New Bitmap(myimage.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
bytImage = ms.ToArray()
ms.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
comm.Parameters.AddWithValue("@Photo", bytImage)
comm.Parameters.AddWithValue("@Remarks", Remarks_TextBox.Text)
comm.Parameters.AddWithValue("@Status", Status_ComboBox.Text)
comm.ExecuteNonQuery()
MessageBox.Show("Saved successful!", "Employee Created", MessageBoxButtons.OK, MessageBoxIcon.Information)
comm.ExecuteNonQuery()
conn.Close()
End Sub
爲什麼執行'comm.ExecuteNonQuery()'命令兩次? –