使用ADO.NET方法來存取資料庫,並在按鈕事件裡加入轉換換行符號的程式碼。
****************************程式碼起始*************************
Dim Conn As OleDbConnection = New OleDbConnection()
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("~/App_Data/changshiidb.mdb")
Conn.Open()
Dim text As String = Replace(TextBox1.Text, vbCrLf, "<br>")
Dim sqlstr As String = "Insert Into 多行(textcont) Values ('" & text & "')"
Dim cmd As OleDbCommand = New OleDbCommand(sqlstr, Conn)
cmd.ExecuteNonQuery()
cmd.Cancel()
Conn.Close()
Conn.Dispose()
****************************程式碼結束*************************
讀取時不需再另外轉換,直接將文字顯示。
****************************程式碼起始*************************
Dim Conn As OleDbConnection = New OleDbConnection()
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("~/App_Data/changshiidb.mdb")
Conn.Open()
Dim sqlstr As String = "select * from 多行"
Dim cmd As OleDbCommand = New OleDbCommand(sqlstr, Conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader()
While dr.Read()
Literal1.Text = dr.Item("textcont")
End While
cmd.Cancel()
dr.Close()
Conn.Close()
Conn.Dispose()
****************************程式碼結束*************************
2009年6月3日 星期三
訂閱:
張貼留言 (Atom)
0 意見:
張貼留言