Dim userTable As DataTable = ds.Tables(\ Dim row As DataRow = userTable.NewRow() Dim cmm As SqlCommand = New SqlCommand() cmm.Connection = conn
cmm.CommandText = \strName & \
Dim reader As SqlDataReader conn.Open()
reader = cmm.ExecuteReader()
If reader.Read() Then
MsgBox(\用户名已存在!\ End If
reader.Close()
row(\ row(\ userTable.Rows.Add(row)
adapter.Update(ds.Tables(\ MsgBox(\注册成功\ Me.Hide() End Sub
(3)新建联系人
Private Sub NewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewBtn.Click If TxtId.Text = \
MsgBox(\学号不能为空\提示\
TxtId.Focus() Return End If
If TxtName.Text = \
MsgBox(\姓名不能为空\提示\
TxtName.Focus() Return End If
If Txtphone.Text = \
MsgBox(\电话不能为空\提示\
Txtphone.Focus() Return End If
If Txtqq.Text = \
MsgBox(\不能为空\提示\ Txtqq.Focus() Return End If
If Txtaddress.Text = \
MsgBox(\地址不能为空\提示\
Txtaddress.Focus() Return End If
Dim connStr As String = _
ConfigurationManager.ConnectionStrings(\ongxunluConnectionString\
Dim conn As SqlConnection = New SqlConnection(connStr) Dim adapter As SqlDataAdapter = New SqlDataAdapter(\* from lianxirentable\ Dim cmd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
Dim ds As DataSet = New DataSet() adapter.Fill(ds, \
Dim userTable As DataTable = ds.Tables(\ Dim row As DataRow = userTable.NewRow()
Dim cmm As SqlCommand = New SqlCommand() cmm.Connection = conn
cmm.CommandText = \& TxtId.Text & \
Dim reader As SqlDataReader
conn.Open()
reader = cmm.ExecuteReader()
If reader.Read() Then
MsgBox(\学号已存在!\ Return End If
reader.Close() ‘获取输入信息
row(\
row(\
If RadioButton1.Checked = True Then row(\ Else
row(\ End If
row(\ row(\
row(\ row(\ row(\ userTable.Rows.Add(row) ’更新到表
adapter.Update(ds.Tables(\ MsgBox(\添加成功\ Me.Hide()
End Sub (4)查看联系人
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.Text = \请选择\
MsgBox(\请选择查询方式\提示\ Exit Sub
ElseIf ComboBox1.Text = \学号\ Dim str As String = TextBox1.Text
Dgvlianxiren.DataSource = TongxunluDataSet1.lianxirentable.Select(\
ElseIf ComboBox1.Text = \姓名\
Dim str As String = TextBox1.Text
Dgvlianxiren.DataSource = TongxunluDataSet1.lianxirentable.Select(\& str & \
End If
If TextBox1.Text = \
MsgBox(\请输入查询条件\警告\ Exit Sub End If
End Sub (5)修改联系人
Private Sub Baocunbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Baocunbtn.Click
Dim row As DataRow = BindingContext(Dgvlianxiren.DataSource, Dgvlianxiren.DataMember).Current.row
'修改行中对应字段的数据 'row(\ row(\
If RadioButton1.Checked = True Then row(\ Else
row(\ End If
row(\ row(\ row(\
row(\ row(\ '提交到数据库
LianxirentableTableAdapter.Update(TongxunluDataSet2.lianxirentable)
TongxunluDataSet2.lianxirentable.AcceptChanges()
End Sub
(6)删除联系人
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MsgBox(\确定要删除此行数据吗?\MsgBoxResult.Ok Then
'得到当前选中行对应的DAtatable中的DataRow
Dim row As DataRow = BindingContext(dgvlianxiren.DataSource,
dgvlianxiren.DataMember).Current.Row '删除此行 row.Delete() '更新到数据库
LianxirentableTableAdapter.Update(TongxunluDataSet3.lianxirentable)
TongxunluDataSet3.lianxirentable.AcceptChanges()
End If
End Sub
四、运行界面及文字说明 (1)登录系统
图1主界面
输入账号密码进入系统,用户名与密码均不能为空,若输入正确则能连接数据库显示“欢迎使用”,若密码错误则显示“密码错误”,若输入的用户错误则显示“没有此用户,请重新输入”