我在做什么-
- 从 excel 表中将 406 行导入到 5 个 sql 表中。
- 导入后,我在按钮单击事件中将数据一一手动保存到 5 个表中的每一个中,并显示在 datagridview 上。
- 保存每条记录后,我正在刷新 datagridview。
我的问题 -
- 记录已正确保存,但 datagridview 仅显示 408 条记录,实际没有。记录是 412。
- 从服务器资源管理器查看时,也只显示 408 条记录。
- 但是表属性显示有 412 行。
- 这个问题只有第一张桌子。
我的代码:-
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()