I made a Boarding House system, everything was going smoothly until I found this error. When I click btnDone I want to save it to my Oracle db. I dont know why I can save boarder_id through boarderpic under dsNewRow into my tblBoarder2, but under dsNewRow2, I can't seem to save it on my other table which is tblAddItems.
我做了一个寄宿公寓系统,一切顺利,直到我发现这个错误。当我点击btnDone时,我想将它保存到我的Oracle数据库中。我不知道为什么我可以通过dsNewRow下的boarderpic将boarder_id保存到我的tblBoarder2中,但是在dsNewRow2下,我似乎无法将它保存在我的另一个表tblAddItems上。
I don't understand how to code this. Can anyone please help? Thanks in advance. I'm actually new to coding and got interested in vb.net since last two months so my experience is quite low.
我不明白如何编码。有人可以帮忙吗?提前致谢。我实际上是编码的新手,并且自从过去两个月以来对vb.net感兴趣所以我的经验很低。
Here's my code:
这是我的代码:
Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim picfaculty As String
Dim filetocopy As String
Dim newcopy As String
filetocopy = picPath
newcopy = Application.StartupPath & "\Images\" & Form3.lblPicname.Text
If System.IO.File.Exists(filetocopy) = True Then
System.IO.File.Copy(filetocopy, newcopy)
picfaculty = Form3.lblPicname.Text
Else
picfaculty = "pic.png"
End If
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("tblboarder2").NewRow() '<--This is the part w/ the error
dsNewRow.Item("boarder_id") = lblID.Text
dsNewRow.Item("lname") = Form3.txtlname.Text
dsNewRow.Item("fname") = Form3.txtfname.Text
dsNewRow.Item("mi") = Form3.txtmi.Text
dsNewRow.Item("age") = Form3.txtage.Text
dsNewRow.Item("gender") = Form3.cboGender.Text
dsNewRow.Item("occupation") = Form3.txtOccupation.Text
dsNewRow.Item("roomnum") = Form3.cboRoomnum.Text
dsNewRow.Item("boarderpic") = picfaculty
ds.Tables("tblboarder2").Rows.Add(dsNewRow)
da.Update(ds, "tblboarder2")
Dim dsNewRow2 As DataRow
dsNewRow2 = ds.Tables("tblAddItems").NewRow()
dsNewRow2.Item("boarder_id") = lblID.Text
dsNewRow2.Item("Item") = "Blanket"
dsNewRow2.Item("Quantity") = Form3.cboBlanket.Text
ds.Tables("tblAddItems").Rows.Add(dsNewRow2)
da.Update(ds, "tblAddItems")
MsgBox("New Record Added to the Database", MsgBoxStyle.Information, "Save")
Me.Close()
Form3.Close()
End Sub
1 个解决方案
#1
0
How certain are you the error is on that line? I am suspicious of the preceding condition. I have used similar code before and found the object reference error occurrs in the file copy:
你在这条线上的错误有多确定?我怀疑上述情况。我之前使用过类似的代码,发现文件副本中出现了对象引用错误:
System.IO.File.Copy(filetocopy, newcopy)
because the file already exists in the destination and its not set to overwrite. You are using the first overload. Try using the second like this:
因为该文件已存在于目标中,并且未设置为覆盖。您正在使用第一个重载。尝试使用第二个像这样:
System.IO.File.Copy(filetocopy, newcopy, true)
And see if your error goes away.
看看你的错误是否消失了。
-d
#1
0
How certain are you the error is on that line? I am suspicious of the preceding condition. I have used similar code before and found the object reference error occurrs in the file copy:
你在这条线上的错误有多确定?我怀疑上述情况。我之前使用过类似的代码,发现文件副本中出现了对象引用错误:
System.IO.File.Copy(filetocopy, newcopy)
because the file already exists in the destination and its not set to overwrite. You are using the first overload. Try using the second like this:
因为该文件已存在于目标中,并且未设置为覆盖。您正在使用第一个重载。尝试使用第二个像这样:
System.IO.File.Copy(filetocopy, newcopy, true)
And see if your error goes away.
看看你的错误是否消失了。
-d