vb.net编一个题库更新软件
有一个考试题库,现在有一些新试题要考到题库里,一题一题输入太慢,像一把考进去,我是把这个题库的表以文本模式输出,如何写一个小程序或方法来完成这个想法。 --------------------编程问答-------------------- excel 导入? --------------------编程问答-------------------- 把文本文档编辑一下,改成标准的表格模式,就可以写程序遍历,转换插入数据库中。 --------------------编程问答-------------------- 一题一题之间用¥@#¥%¥等特殊字符分割开来,然后一个个读取。。。。 --------------------编程问答-------------------- 考试题库是一个数据库吗?新试题要考到题库里,那可以把新考题复制到一个textbox里面,然后通过数据库操作把考题导入到数据库里面。浏览也可以通过一个文本绑定的方式显示出来。
数据库设计:考试题库_mdb,access数据库
考题表:tests 字段:考题编号(key)
考题内容
数据操作: 通过textbox导入新考题到考题表tests里面
通过绑定实现浏览考题功能
界面设计:frmmain——主要功能浏览考题
控件:『textbox』txtshow(浏览载体)
『textbox』txtid
『button』 btnsave(单击保存修改)
关键代码:
Private Sub FrmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mydb As New DataSet
Dim path As String = Application.StartupPath.ToString & "\考试题库_mdb.mdb"
Dim myconnection As New OleDbConnection("provider=microsoft.jet.OLEDB.4.0;" & "data source=" & path )
Dim strsql As String = "select 考题编号,考题内容 from tests"
Dim information As OleDbDataAdapter = New OleDbDataAdapter(strsql, myconnection)
information.Fill(db, "tests")
Me.txtshow.DataBindings.Add("text", db, "tests.考题编号")
Me.TxtBirth.DataBindings.Add("text", db, "tests.考题内容")
End Sub
public Sub connection(ByVal sqlstr As String)
Dim strcon As String
Dim path As String
path = Application.StartupPath.ToString & "\考试题库_mdb.mdb"
strcon = "provider=microsoft.jet.OLEDB.4.0;" & "data source=" & path
Dim mycon As OleDbConnection = New OleDbConnection(strcon)
Dim mycommand As New OleDbCommand(sqlstr, mycon)
Dim information As OleDbDataAdapter = New OleDbDataAdapter(mycommand)
mycon.Open()
mycommand.ExecuteReader()
mycon.Close()
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Dim strsql As String = String.Format("update [info] set 考题编号='{0}',考题内容='{1}'", txtid,txtshow)
Dim friends As New Myfriend
connection(strsql)
End Sub
注意,你可以用这个btnsave添加新考题
添加窗体:frmadd—— 控件『textbox』txtidadd,txttests
『button』 btnadd
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim strsql As String = String.Format("INSERT INTO text(考题编号,考题内容) VALUES ('{0}','{1}')", txtidadd.text,txttests.text)
connection(strsql)
End Sub
主体就这么多了,防错就需要自己努力了。希望对你有点帮助。 --------------------编程问答-------------------- 你这样说别人是听不明白的,不知是不是你昨天的程序
接你昨天的文件
Dim sr As TextReader = New StreamReader("c:\7.txt")
Dim line1 As String = ""
Dim line2 As String = ""
mycom.Connection.ConnectionString = constr '为这个连接字符串重新赋值
mycon.Open() '重新打开这个联接
Dim k As Integer = 0
Do
line1 = ""
line2 = ""
line1 = sr.ReadLine
'MsgBox(line1)
line2 = sr.ReadLine
If line1 <> "" And line2 <> "" Then
mycom.CommandText = "insert into testinsert(STNR,STDA) values('" & line1 + "','" + line2 + "')"
mycom.ExecuteNonQuery() '用不返回结果的查询语句来插入一条记录
End If
Loop Until line1 Is Nothing
sr.Close()
mycon.Close()
MsgBox("数据库更新完毕!")
补充:.NET技术 , VB.NET