End Sub
}
// 个人信息录入代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox2.Text = "" Then
MessageBox.Show("必填项目不得为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
Dim myview As DataView
myview = New DataView(DataSet51.xuesheng, "", "xuehao", DataViewRowState.CurrentRows)
Dim rowindex As Integer = myview.Find(TextBox1.Text)
If rowindex = -1 Then
Beep()
MsgBox("数据库中未找到与此记录重复的数据,可以存入!")
Dim str1, str2 As String
str1 = "insert into xuesheng(xuehao, xingming, xingbie, banji, nianling"
str2 = "values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & ComboBox1.Text & "','" & ComboBox2.Text & "','" & TextBox3.Text & "'"
If TextBox4.Text <> "" Then
str1 = str1 & ",dianhua"
str2 = str2 & ",'" & TextBox4.Text & "'"
End If
If TextBox5.Text <> "" Then
str1 = str1 & ",zhuzhi"
str2 = str2 & ",'" & TextBox5.Text & "'"
End If
str1 = str1 & ")" & str2 & ")"
Try
Dim com As New OleDbCommand(str1, mycon)
mycon.Open()
com.ExecuteNonQuery()
mycon.Close()
MessageBox.Show("信息已成功存入数据库", "恭喜", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
DataSet51.Clear()
OleDbDataAdapter2.Fill(DataSet51)
Catch
mycon.Close()
MessageBox.Show(Err.Description, "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
End Try
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
ComboBox1.ResetText()
ComboBox2.ResetText()
Else
MsgBox("数据库中此记录已存在,请重新输入!")
End If
End Sub
End Class
成绩打印代码
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Label2.Text = "科目编号为" & ComboBox1.Text & "的课程全体学生的成绩为:"
With Me.CrystalReportViewer2
If Me.ComboBox1.SelectedItem(0) Is System.DBNull.Value Then
.SelectionFormula = "isnull ({chengji.kemubianhao})"
Else
.SelectionFormula = "{chengji.kemubianhao}='" & Me.ComboBox1.SelectedItem(0) & "'"
End If
.RefreshReport()
End With
End Sub