用到数据控件DataSet,OleDbConnection,OleDbDataAdapter
'组合搜索
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles BtnOK.Click
Dim str As String
Dim type1 As String
str = "select * from telecode where 1=1 "
If Me.txName.Text <> "" Then
str = str & " and name like '%" &
Me.txName.Text & "%'"
End If
If Me.txDept.Text <> "" Then
str = str & " and dept like '%" &
Me.txDept.Text & "%'"
End If
If Me.txAddr.Text <> "" Then
str = str & " and address like '%"
& Me.txAddr.Text & "%'"
End If
If Me.txTele.Text <> "" Then
str = str & " and (telephone like '%"
& Me.txTele.Text & "%' or mobile
like '%" & Me.txTele.Text &
"%')"
End If
If Me.cbxType.SelectedItem <> ""
Then
type1 = Me.cbxType.SelectedIndex + 1
str = str & " and type = '" & type1
& "'"
End If
OleDbConnection1.Open()
Console.Write(str)
OleDbDataAdapter1.SelectCommand.CommandText = str
OleDbDataAdapter1.SelectCommand.ExecuteNonQuery()
DataSet1.Clear()
OleDbDataAdapter1.Fill(DataSet1)
OleDbConnection1.Close()
' DataView1.Table = DataSet1.Tables(0)
'
showpostion()
'ComboBox1.DataSource = objds.Tables(0)
'ComboBox1.DisplayMember =
objds.Tables(0).Columns(1).ToString
'Label1.Text = objds.Tables(0).Columns(1).ColumnName
Dim ds As DataSet
ds = DataSet1
If Not ds Is Nothing Then
Me.DataGrid1.PreferredColumnWidth = Me.DataGrid1.Width /
ds.Tables(0).Columns.Count
Me.DataGrid1.DataSource = ds.Tables(0)
Else
MsgBox("没有符合要求的记录!", MsgBoxStyle.OKOnly, "提示")
Me.DataGrid1.DataSource = Nothing
End If
'
LabAcc.Text = ds.Tables(0).Columns.Count
End Sub
'增加记录
Private Sub BtAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtAdd.Click
If txName.Text = "" Or (txTele.Text = "" And txMobile.Text = "")
Then
MsgBox("请填充完成数据", MsgBoxStyle.Information, "提示")
txTele.Focus()
Exit Sub
Else
Dim sex1 As Integer
Dim str, type1 As String
If RadioBt1.Checked Then
sex1 = 0
Else
sex1 = -1
End If
If Me.cbxType.SelectedItem <> ""
Then
type1 = Me.cbxType.SelectedIndex + 1
End If
Str = "insert into telecode (
id,name,sex,dept,address,telephone,mobile,tnote,type ) values ( "
& _
txId.Text & ", '" & txName.Text
& "', " & sex1 & ",
'" & _
txDept.Text & "', '" & txAddr.Text
& "', '" & txTele.Text
& "', '" & _
|