vb6.0 用文本框给datagrid添加数据
vb6.0用文本框给datagrid添加数据,怎样判断文本框的数据在datagrid有没有要加入的数据,如果有弹出提示,没有就加入数据?代码怎样写?...
vb6.0 用文本框给datagrid添加数据,怎样判断文本框的数据在datagrid有没有要加入的数据,如果有弹出提示,没有就加入数据?代码怎样写?
展开
3个回答
展开全部
datagrid+ 数个TEXTBOX一个cmd 实现
Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Private Sub Command1_Click()
If Text1(0).Text = "" Or Text1(1) = "" Or Text1(2) = "" Then
MsgBox "请输入员工信息不能为空", 48, "提示信息"
Else
Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Con.Open
Set Rs = Con.Execute("insert into tb_laborage (员工姓名,所属部门,月份,基本工资,奖金) values('" + Text1(0) + "','" + Text1(1) + "','" + Text1(2) + "','" + Text1(3) + "','" + Text1(4) + "')")
Con.Close
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage order by 编号"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Private Sub Command1_Click()
If Text1(0).Text = "" Or Text1(1) = "" Or Text1(2) = "" Then
MsgBox "请输入员工信息不能为空", 48, "提示信息"
Else
Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Con.Open
Set Rs = Con.Execute("insert into tb_laborage (员工姓名,所属部门,月份,基本工资,奖金) values('" + Text1(0) + "','" + Text1(1) + "','" + Text1(2) + "','" + Text1(3) + "','" + Text1(4) + "')")
Con.Close
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage order by 编号"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
datagrid+ 数个TEXTBOX一个cmd 实现
Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Private Sub Command1_Click()
If Text1(0).Text = "" Or Text1(1) = "" Or Text1(2) = "" Then
MsgBox "请输入员工信息不能为空", 48, "提示信息"
Else
Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Con.Open
Set Rs = Con.Execute("insert into tb_laborage (员工姓名,所属部门,月份,基本工资,奖金) values('" + Text1(0) + "','" + Text1(1) + "','" + Text1(2) + "','" + Text1(3) + "','" + Text1(4) + "')")
Con.Close
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage order by 编号"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Private Sub Command1_Click()
If Text1(0).Text = "" Or Text1(1) = "" Or Text1(2) = "" Then
MsgBox "请输入员工信息不能为空", 48, "提示信息"
Else
Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Con.Open
Set Rs = Con.Execute("insert into tb_laborage (员工姓名,所属部门,月份,基本工资,奖金) values('" + Text1(0) + "','" + Text1(1) + "','" + Text1(2) + "','" + Text1(3) + "','" + Text1(4) + "')")
Con.Close
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage order by 编号"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_Test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_laborage"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Visible = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DataGrid控件在读取数据的时候,会发生读取数据不正确的情况,这是由于控件本身决定的,一般是用控件的DataGrid1_Click事件读取数据,为什么呢?经过昨天一天的探讨,知道了DataGrid控件的Row和Col值是不确定的,我读取过记录的Row和Col值,发现在控件拉动滚动条时,控件的Row和Col值的确是在发生变化的。
后来资料介绍,可以用控件的DataGrid1_RowColChange事件读取数据,但是这种读取数据的方法只能读取被点击的记录的字段值,而不能读取整个DataGrid控件显示的所有字段:
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Text1(0).Text = DataGrid1.Text
End Sub
在Text1(0).Text文本框显示的是你刚刚点击的记录字段值(注意只是一个字段的值),如果你认为用控件的Row和Col属性来读取,上面说过由于它的Row和Col值不确定,因此控件是不能支持这种读取方法。
后来资料介绍,可以用控件的DataGrid1_RowColChange事件读取数据,但是这种读取数据的方法只能读取被点击的记录的字段值,而不能读取整个DataGrid控件显示的所有字段:
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Text1(0).Text = DataGrid1.Text
End Sub
在Text1(0).Text文本框显示的是你刚刚点击的记录字段值(注意只是一个字段的值),如果你认为用控件的Row和Col属性来读取,上面说过由于它的Row和Col值不确定,因此控件是不能支持这种读取方法。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询