写入模式为覆盖会出现这个现象
创新互联公司-专业网站定制、快速模板网站建设、高性价比饶阳网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式饶阳网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖饶阳地区。费用合理售后完善,10年实体公司更值得信赖。
要使用添加模式
就会累加了
写入: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
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim f As New FileInfo("d:\doc.xml")
If f.Exists = False Then
f.Create()
f.Refresh()
End If
Dim s As String = ""
Dim sw As StreamWriter = f.CreateText()
s = "?xml version=""1.0"" encoding=""GB2312""?"
sw.WriteLine(s)
sw.WriteLine("doc")
sw.WriteLine(" assembly")
sw.WriteLine("userId34/userId")
sw.WriteLine("userName张三/userName")
sw.WriteLine("qxbz1/qxbz")
sw.WriteLine(" /assembly")
sw.WriteLine("/doc")
sw.Flush()
sw.Close()
Process.Start("d:\doc.xml")
End Sub
End Class
Imports System.Runtime.InteropServices
Public Class MemoryEditor
Inherits WINAPI.NativeMethods
Private phwnd As IntPtr
Private Buffer As Byte()
Private BytesRead As IntPtr
Private BytesWrite As IntPtr
''' summary创建内存编辑器/summary
''' param name="processHwnd"进程句柄/param
Sub New(processHwnd As IntPtr)
Me.phwnd = processHwnd
End Sub
''' summary根据指定偏移量读取内存基址/summary
''' param name="addr"内存地址/param
''' param name="offsets"偏移量数组/param
Public Function ReadBaseAddress(addr As IntPtr, offsets() As Integer) As IntPtr
Dim address As IntPtr = ReadMemoryToInteger(addr)
For Each offset As Integer In offsets
address = address.ToInt32 + offset
address = ReadMemoryToInteger(address)
If address = IntPtr.Zero Then
Dim errInfo As String = "内存偏移量[" Hex(offset) "]错误!"
Throw New Exception(errInfo)
End If
Next
Return address
End Function
''' summary读取4字节内存数值/summary
''' param name="addr"内存地址/param
Public Function ReadMemoryToInteger(addr As IntPtr) As Integer
Buffer = New Byte(3) {}
ReadProcessMemory(phwnd, addr, Buffer, 4, BytesRead)
Return BitConverter.ToInt32(Buffer, 0)
End Function
''' summary读取4字节内存数组/summary
''' param name="addr"内存地址/param
Public Function ReadMemoryToBytes(addr As IntPtr) As Byte()
Buffer = New Byte(3) {}
ReadProcessMemory(phwnd, addr, Buffer, 4, BytesRead)
Return Buffer
End Function
''' summary将内存值数组写入指定地址/summary
''' param name="addr"内存地址/param
''' param name="buffer"内存值数组/param
Public Function WriteMemoryByBytes(addr As IntPtr, buffer As Byte()) As Boolean
Return WriteProcessMemory(phwnd, addr, buffer, buffer.Length, BytesWrite)
End Function
End Class
Namespace WINAPI
Public MustInherit Class NativeMethods
DllImport("kernel32.dll", SetLastError:=True) _
Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
Out() ByVal lpBuffer() As Byte, _
ByVal dwSize As Integer, _
ByRef lpBytesRead As Integer) As Boolean
End Function
DllImport("kernel32.dll", SetLastError:=True) _
Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
ByVal lpBuffer As Byte(), _
ByVal nSize As Integer, _
Out() ByRef lpBytesWritten As IntPtr) As Boolean
End Function
End Class
End Namespace
是不是内存读写代码有问题!用上面的代码试试,我以前写的;
调用方法:
Dim mem As New MemoryEditor(进程句柄)
Dim offsets As Integer() = {H1, H2, H3} '{一级基址,二级基址,三级基址}
Dim baseaddr As IntPtr = mem.ReadBaseAddress(内存地址, offsets)
Dim value As Integer = mem.ReadMemoryToInteger(baseaddr)
1、首先,你得做一个oledbconnection对象,这个对象有个连接字符串的属性,你需要设置
2、做一个oledbcommand对象,这个对象有个操作字符串(SQL语句)需要设置
3、打开oledbconnection对象
4、执行oledbcommand对象
5、关闭oledbconnection对象
程序结束,希望对你有帮助
使用.net下的system.sql.sqlclint类库下的sqlconnent;sqlcommand类进行写入操作