1、實現(xiàn)上傳按鈕方法代碼。
10年積累的做網(wǎng)站、成都做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先做網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有石林免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
2、判斷圖片對象是否為空代碼。
3、取得數(shù)據(jù)庫字段 dt.Rows(0)("Pic")方法代碼。
4、字節(jié)數(shù)組轉(zhuǎn)換為Image類型方法代碼。
5、處理SQL中操作Image類型方法代碼。
6、實現(xiàn)的上傳結(jié)果。
VB.NET打開二進制文件用fileopen完成,打開二進制文件的形式為:openmode.binary
讀取二進制文件用的是fileget方法,寫入二進制文件用的是fileput方法。
應(yīng)用示例:將一批隨機數(shù)保存在一個dat文件中,然后再將其提取到文本框中。
二進制文件的讀寫一批隨機數(shù)的存取,程序為:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, i, fn As Integer
Dim s As String = ""
fn = FreeFile()
FileOpen(fn, "d:\data.dat", OpenMode.Binary)
For i = 1 To 8
x = Int(Rnd() * 100)
s = s + Str(x)
FilePut(fn, x)
Next
FileClose(fn)
TextBox1.Text = s
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim x, fn As Integer
Dim s As String = ""
fn = FreeFile()
FileOpen(fn, "d:\data.dat", OpenMode.Binary)
Do While Not EOF(fn)
FileGet(fn, x)
s = s + Str(x) + " "
Loop
FileClose(fn)
TextBox1.Text = s
End Sub
imports System.IO
讀取指定文件
'
'讀取指定文本文件
Public Function readtext(ByVal path As String)
If path = "" Then
readtext = "操作失??!"
Exit Function
End If
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim str As String
str = sr.ReadToEnd.ToString
sr.Close()
fs.Close()
readtext = str
Else
readtext = "操作失?。?
End If
Catch ex As Exception
readtext = "操作失?。?
End Try
End Function
'向指定文件寫入數(shù)據(jù)
Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)
If path = "" Then
writetext = "操作失?。?
Exit Function
End If
Dim op As FileMode
Select Case opi
Case 1
op = FileMode.Append
Case 2
op = FileMode.Create
Case Else
op = FileMode.Create
End Select
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, op)
Dim sr As New StreamWriter(fs)
sr.WriteLine(msg)
sr.Close()
fs.Close()
writetext = "操作完成!"
Else
writetext = "操作失?。?
End If
Catch ex As Exception
writetext = "操作失??!"
End Try
End Function
1、新建一個標準的VB EXE工程,只有一個Form,F(xiàn)orm上有兩個按鈕:Command1和Command2。
2、雙擊Command1添加如下代碼
Private Sub Command1_Click()
Dim strFile? ? ?As String
Dim intFile? ? ?As Integer
Dim strData? ? ?As String
strFile = "c:\學(xué)生成績.txt"
intFile = FreeFile
Open strFile For Input As intFile
strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)
Debug.Print strData
Close intFile
End Sub
3、按F8開始單步調(diào)試代碼,點擊Command1,進入單步調(diào)試功能,
4、多次按下F8或直接按下F5運行完成,就完成了讀取文本文件內(nèi)容并輸出到立即窗口。
添加spire.doc.dll為引用,在vb.net中讀取指定word文檔的內(nèi)容到?txt文件,代碼示例如下:
'加載Word文檔
Dim doc As Document = New Documentdocument.LoadFromFile("測試文檔.docx")
'使用GetText方法獲取文檔中的所有文本
Dim s As String = doc.GetText
File.WriteAllText("文本1.txt", s.ToString)