
有关vb数据库
本人编一个小软件,需要用数据库保存一些数据。如何用VB建立一个数据库,向里面导入数据,然后将数据库你的数据全部显示出来?帮帮忙,我初学者……打错了一个字……数据库里(你)...
本人编一个小软件,需要用数据库保存一些数据。
如何用VB建立一个数据库,向里面导入数据,然后将数据库你的数据全部显示出来?
帮帮忙,我初学者……
打错了一个字……数据库里(你)的数据
可以用VB新生成一个数据库吗? 展开
如何用VB建立一个数据库,向里面导入数据,然后将数据库你的数据全部显示出来?
帮帮忙,我初学者……
打错了一个字……数据库里(你)的数据
可以用VB新生成一个数据库吗? 展开
展开全部
Dim i, j, s2 As Integer
Dim con As New ADODB.Connection
Dim c, cc, s1 As String
Private Sub Command5_Click()
End
End Sub
Private Sub DataGrid1_Click()
If Adodc1.Recordset.RecordCount > 0 Then
For j = 0 To 5
Text1(j).Text = Adodc1.Recordset.Fields(j)
Next j
End If
End Sub
Private Sub Form_Load()
s1 = "人" + "员表"
Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
Adodc1.RecordSource = "select 编号,姓名,年龄, 学历,年级,入学时间 from " & s1 & " order by '编号'"
Adodc1.Refresh
Form1.Show
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "无人员记录", vbOKOnly, "提示信息"
Else
Set DataGrid1.DataSource = Adodc1
End If
Text1(0).SetFocus
End Sub
Private Sub Command1_Click()
For i = 0 To 5
Text1(i).Text = ""
Next i
Adodc1.RecordSource = "select * from " & s1 & " order by 编号"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveLast
Text1(0).Text = "G" + Format((Val(Right(Trim(Adodc1.Recordset.Fields("编号")), 4)) + 1), "0000")
Else
Text1(0).Text = "G0001"
End If
End Sub
Private Sub Command2_Click()
If Adodc1.Recordset.EOF = False Then
c = MsgBox("您确认要删除该记录吗?", vbOKCancel, "删除提示信息")
If c = vbOK Then
Adodc1.Recordset.Delete
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
End If
Else
MsgBox "当前数据库中没有可删除的数据记录", vbOKOnly, "提示信息"
End If
End Sub
Private Sub Command3_Click()
If Text1(0).Text = "" Or Text1(1).Text = "" Then
MsgBox "请选择需要改动的记录信息!", vbOKOnly, "错误提示"
Else
c = MsgBox("确定要修改该记录吗?", vbOKCancel, "提示信息")
If c = vbOK Then '如果确认修改的话进行修改操作
If Text1(1).Text = "" Then
MsgBox "姓名不能为空值!", 48, "修改信息提示"
Else
'连接所要修改的数据库
con.Open "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
'开始修改数据库
con.Execute ("UPDATE " & s1 & " SET 姓名='" & Text1(1).Text & "',年龄=" & Text1(2).Text & ",学历='" & Text1(3).Text & "',年级=" & Text1(4).Text & ", 入学时间='" & Text1(5).Text & "' where 编号='" & Trim(Text1(0)) & "'")
MsgBox "信息修改成功", 64, "修改信息提示"
con.Close
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
End If
End If
End If
End Sub
Private Sub Command4_Click()
Adodc1.RecordSource = "select * from 人员表 where 编号='" + Text1(0).Text + "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "该信息已存在,信息保存不成功", 64, "保存信息提示"
Else
cc = MsgBox("您确定要保存该信息吗?", 33, "信息保存提示")
If cc = vbOK Then
If Text1(1).Text = "" Or Text1(2).Text = "" Or Text1(3).Text = "" Or Text1(4).Text = "" Or Text1(5).Text = "" Then
MsgBox "请确认,人员的姓名、年龄、学历、年级和入学时间不能为空", 48, "保存信息提示"
Else
con.Open "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
con.Execute ("insert into 人员表 values('" & Text1(0).Text & "','" & Text1(1).Text & "','" & Text1(2).Text & "','" & Text1(3).Text & "','" & Text1(4).Text & "', '" & Text1(5).Text & "')")
MsgBox "信息修改成功", 64, "修改信息提示"
con.Close
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
End If
Else
End If
End If
Set DataGrid1.DataSource = Adodc1
End Sub
这个是我做的,应该可以用,用的是VB6.0和SQL
用DataGrid1显示记录,text显示相应记录的内容,可以进行添加,修改,删除
Dim con As New ADODB.Connection
Dim c, cc, s1 As String
Private Sub Command5_Click()
End
End Sub
Private Sub DataGrid1_Click()
If Adodc1.Recordset.RecordCount > 0 Then
For j = 0 To 5
Text1(j).Text = Adodc1.Recordset.Fields(j)
Next j
End If
End Sub
Private Sub Form_Load()
s1 = "人" + "员表"
Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
Adodc1.RecordSource = "select 编号,姓名,年龄, 学历,年级,入学时间 from " & s1 & " order by '编号'"
Adodc1.Refresh
Form1.Show
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "无人员记录", vbOKOnly, "提示信息"
Else
Set DataGrid1.DataSource = Adodc1
End If
Text1(0).SetFocus
End Sub
Private Sub Command1_Click()
For i = 0 To 5
Text1(i).Text = ""
Next i
Adodc1.RecordSource = "select * from " & s1 & " order by 编号"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveLast
Text1(0).Text = "G" + Format((Val(Right(Trim(Adodc1.Recordset.Fields("编号")), 4)) + 1), "0000")
Else
Text1(0).Text = "G0001"
End If
End Sub
Private Sub Command2_Click()
If Adodc1.Recordset.EOF = False Then
c = MsgBox("您确认要删除该记录吗?", vbOKCancel, "删除提示信息")
If c = vbOK Then
Adodc1.Recordset.Delete
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
End If
Else
MsgBox "当前数据库中没有可删除的数据记录", vbOKOnly, "提示信息"
End If
End Sub
Private Sub Command3_Click()
If Text1(0).Text = "" Or Text1(1).Text = "" Then
MsgBox "请选择需要改动的记录信息!", vbOKOnly, "错误提示"
Else
c = MsgBox("确定要修改该记录吗?", vbOKCancel, "提示信息")
If c = vbOK Then '如果确认修改的话进行修改操作
If Text1(1).Text = "" Then
MsgBox "姓名不能为空值!", 48, "修改信息提示"
Else
'连接所要修改的数据库
con.Open "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
'开始修改数据库
con.Execute ("UPDATE " & s1 & " SET 姓名='" & Text1(1).Text & "',年龄=" & Text1(2).Text & ",学历='" & Text1(3).Text & "',年级=" & Text1(4).Text & ", 入学时间='" & Text1(5).Text & "' where 编号='" & Trim(Text1(0)) & "'")
MsgBox "信息修改成功", 64, "修改信息提示"
con.Close
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
End If
End If
End If
End Sub
Private Sub Command4_Click()
Adodc1.RecordSource = "select * from 人员表 where 编号='" + Text1(0).Text + "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "该信息已存在,信息保存不成功", 64, "保存信息提示"
Else
cc = MsgBox("您确定要保存该信息吗?", 33, "信息保存提示")
If cc = vbOK Then
If Text1(1).Text = "" Or Text1(2).Text = "" Or Text1(3).Text = "" Or Text1(4).Text = "" Or Text1(5).Text = "" Then
MsgBox "请确认,人员的姓名、年龄、学历、年级和入学时间不能为空", 48, "保存信息提示"
Else
con.Open "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
con.Execute ("insert into 人员表 values('" & Text1(0).Text & "','" & Text1(1).Text & "','" & Text1(2).Text & "','" & Text1(3).Text & "','" & Text1(4).Text & "', '" & Text1(5).Text & "')")
MsgBox "信息修改成功", 64, "修改信息提示"
con.Close
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
End If
Else
End If
End If
Set DataGrid1.DataSource = Adodc1
End Sub
这个是我做的,应该可以用,用的是VB6.0和SQL
用DataGrid1显示记录,text显示相应记录的内容,可以进行添加,修改,删除

2025-02-18 广告
表面污染分析包括评估表面上存在的颗粒、残留物或物质。通过利用显微镜、光谱学和色谱法等技术,分析人员可以识别和表征污染物,以确定其成分和来源。这种分析在电子、制药和制造等各个行业中至关重要,以确保产品质量、性能和安全性。了解表面污染有助于实施...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询