我在做什么 -
我的问题 -
我的代码: -
cmd.CommandText = String.Empty
cmd.Parameters.Clear()
cmd.CommandText = "INSERT into pd([Adm No],[DOA],[Name],[Course],[Fees Due],[Concession],[Contact No 1]," & _
"[Contact No 2],[E-Mail],[Year of Passing],[Address],[DOB],[College])" & _
" values(@admno,@doa,@name,@course,@totalfees,@concession,@contactno1,@contactno2,@email,@yop," & _
"@address,@dob,@college)"
cmd.Parameters.AddWithValue("@admno", i.ToString)
cmd.Parameters.AddWithValue("@doa", date_format.format_date(doa.Value.Date))
cmd.Parameters.AddWithValue("@name", txt_name.Text)
cmd.Parameters.AddWithValue("@course", combo_course.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@totalfees", txt_totalfees.Text)
cmd.Parameters.AddWithValue("@concession", txt_concession.Text)
cmd.Parameters.AddWithValue("@contactno1", txt_contact1.Text)
cmd.Parameters.AddWithValue("@contactno2", txt_contact2.Text)
cmd.Parameters.AddWithValue("@email", txt_email.Text)
cmd.Parameters.AddWithValue("@yop", txt_yop.Text)
cmd.Parameters.AddWithValue("@address", txt_address.Text)
cmd.Parameters.AddWithValue("@dob", date_format.format_date(dob.Value.Date))
cmd.Parameters.AddWithValue("@college", txt_college.Text)
If con.State = ConnectionState.Closed Then
con.Open()
End If
cmd.Connection = con
cmd.ExecuteNonQuery()
'save fees details
cmd.CommandText = String.Empty
cmd.Parameters.Clear()
cmd.CommandText = "INSERT into fees([Adm No],[Name],[Fees Due],[Fees Paid],[No of Installments]," & _
"[Installment Amounts],[Receipt Nos],[Dates of Transaction],[Mode],[Bank],[Due Date]" & _
",[Total Fees],[Concession],[Cheque No],[Course])" & _
" values(@admno,@name,@feesdue,@feespaid,@noi,@instamnt,@rcno,@dot,@mode,@bank,@dd," & _
"@total,@concession,@chqno,@course)"
cmd.Parameters.AddWithValue("@admno", i.ToString)
cmd.Parameters.AddWithValue("@name", txt_name.Text)
cmd.Parameters.AddWithValue("@feesdue", (CInt(txt_totalfees.Text) - CInt(txt_concession.Text)))
cmd.Parameters.AddWithValue("@feespaid", CInt(0))
cmd.Parameters.AddWithValue("@noi", CInt(0))
cmd.Parameters.AddWithValue("@instamnt", "")
cmd.Parameters.AddWithValue("@rcno", "")
cmd.Parameters.AddWithValue("@dot", "")
cmd.Parameters.AddWithValue("@mode", "")
cmd.Parameters.AddWithValue("@bank", "")
cmd.Parameters.AddWithValue("@dd", "")
cmd.Parameters.AddWithValue("@total", CInt(txt_totalfees.Text))
cmd.Parameters.AddWithValue("@concession", txt_concession.Text)
cmd.Parameters.AddWithValue("@chqno", "")
cmd.Parameters.AddWithValue("@course", combo_course.SelectedItem.ToString)
If con.State = ConnectionState.Closed Then
con.Open()
End If
cmd.Connection = con
cmd.ExecuteNonQuery()
'save photo
If Not PictureBox1.Image Is Nothing Then
cmd.CommandText = String.Empty
cmd.Parameters.Clear()
cmd.CommandText = "Insert into img values(@adm,@name,@imge)"
Dim para As New SqlCeParameter("imge", SqlDbType.Image)
Dim ms As New MemoryStream
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
Dim data As Byte() = ms.GetBuffer
para.Value = data
cmd.Parameters.AddWithValue("@adm", lb_admno.Text)
cmd.Parameters.AddWithValue("@name", txt_name.Text)
cmd.Parameters.Add(para)
If con.State = ConnectionState.Closed Then
con.Open()
End If
cmd.Connection = con
cmd.ExecuteNonQuery()
Else
cmd.CommandText = String.Empty
cmd.Parameters.Clear()
cmd.CommandText = "Insert into img values(@adm,@name,@imge)"
Dim para As New SqlCeParameter("imge", SqlDbType.Image)
Dim ms As New MemoryStream
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
Dim data As Byte() = ms.GetBuffer
para.Value = data
cmd.Parameters.AddWithValue("@adm", lb_admno.Text)
cmd.Parameters.AddWithValue("@name", txt_name.Text)
cmd.Parameters.Add(para)
If con.State = ConnectionState.Closed Then
con.Open()
End If
cmd.Connection = con
cmd.ExecuteNonQuery()
End If
cmd.CommandText = String.Empty
cmd.Parameters.Clear()
cmd.CommandText = "insert into attend values(@adm,@name,@course,@dt,@stat)"
cmd.Parameters.AddWithValue("@adm", lb_admno.Text)
cmd.Parameters.AddWithValue("@name", txt_name.Text)
cmd.Parameters.AddWithValue("@course", combo_course.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@dt", "")
cmd.Parameters.AddWithValue("@stat", "")
If con.State = ConnectionState.Closed Then
con.Open()
End If
cmd.Connection = con
cmd.ExecuteNonQuery()
cmd.CommandText = String.Empty
cmd.Parameters.Clear()
cmd.CommandText = "insert into testdb values(@adm,@name,@course,@tname,@tdate,@marksob,@marksout)"
cmd.Parameters.AddWithValue("@adm", lb_admno.Text)
cmd.Parameters.AddWithValue("@name", txt_name.Text)
cmd.Parameters.AddWithValue("@course", combo_course.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@tname", "")
cmd.Parameters.AddWithValue("@tdate", "")
cmd.Parameters.AddWithValue("@marksob", "")
cmd.Parameters.AddWithValue("@marksout", "")
If con.State = ConnectionState.Closed Then
con.Open()
End If
cmd.Connection = con
cmd.ExecuteNonQuery()
答案 0 :(得分:0)
问题出在导入记录的代码中。我正在读取excel文件的单元格并将它们插入到五个表中。
只有在我逐个导入所有五个表中的记录时才会出现问题,但是如果我只将记录导入到三个表中,则不会出现问题。
这解决了我的问题,但我不知道背后的实际原因。为什么我不能一个接一个地将记录导入五个表?如果有人发现错误背后的原因,请发表评论。