vb.net如何写入数据 vb读取数据库
vb.net 怎么写入数据库数据
使用.net下的system.sql.sqlclint类库下的sqlconnent;sqlcommand类进行写入操作
创新互联-专业网站定制、快速模板网站建设、高性价比鱼台网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式鱼台网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖鱼台地区。费用合理售后完善,十余年实体公司更值得信赖。
vb.net中,读取和写入文件
写入:Dim sr As New IO.StreamWriter(Application.StartupPath "/写入的文本.txt")
sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath "/msg.txt")) Then
Dim fm As New IO.FileStream(Application.StartupPath "/读取的文本.txt", FileMode.Open)
Dim sr As IO.StreamReader = New IO.StreamReader(fm)
Do While sr.Peek() = 0
TextBox1.Text = sr.ReadLine() (读取文本到文本框)
Loop end if
vb.net 写入mdb数据库
1、首先,你得做一个oledbconnection对象,这个对象有个连接字符串的属性,你需要设置
2、做一个oledbcommand对象,这个对象有个操作字符串(SQL语句)需要设置
3、打开oledbconnection对象
4、执行oledbcommand对象
5、关闭oledbconnection对象
程序结束,希望对你有帮助
vb.net怎么往已经建立好的dat文件里写东西,还不覆盖原本的数据?
如果想继续编辑之前的文档,在TXT文件尾部继续添加文本,那么还需要在函数后边加个参数。
VB 代码
方法1:
Dim sw As StreamWriter = New StreamWriter("C:\temp\test.txt")
sw.Write("abc" vbCrLf)
sw.Close()
Dim sw2 As StreamWriter = New StreamWriter("C:\temp\test.txt", True)
sw2.Write("456" vbCrLf)
sw2.Close()
方法2:
My.Computer.FileSystem.WriteAllText("test.txt", "This is test Text", True)
方法3:
System.IO.File.AppendAllText("c:\temp\test.txt", "this is extra test file")
详见:“网页链接”
VB.NET DATAGRIDVIEW写入数据库
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlStr As String = "insert into tb values("
Dim i As Integer
For i = 0 To DataGridView1.Columns.Count - 1
sqlStr = "'" DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(i) "'"
If i DataGridView1.Columns.Count - 1 Then sqlStr = ","
Next
sqlStr = ")"
Dim con As New SqlConnection(connectionString) '这个自己写去
con.Open()
Dim cmd As New SqlCommand(sqlStr, con)
Try
Dim result As Integer = cmd.ExecuteNonQuery()
If result 0 Then
MsgBox "添加数据成功"
Else
MsgBox "添加数据失败"
End If
Catch (ex As Exception)
MsgBox "添加数据过程发生异常,原因:" ex.Message
End Try
End Sub
新闻标题:vb.net如何写入数据 vb读取数据库
分享链接:http://scjbc.cn/article/hgioii.html