神魂顛倒論壇logo

icon
首頁Microsoft 應用技術區資料庫 MS SQL → [求助]ASP.NET和SQL Server2000 留言板 程式碼,可以幫我看看嗎?

雷射溶脂 | 瘦小腹 | 植髮 | 眼袋 | 玻尿酸 | 電波拉皮 | Flash | 購物車 | Flash Player 11.2 | 豐胸 |

下一主題 上一主題


[求助]ASP.NET和SQL Server2000 留言板 程式碼,可以幫我看看嗎?


簡版






要要輸入新增留言的webForm1 + 下面是要顯示 已留言的留言內容
-------------------------------------------------------------------------------------------------

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form 設計工具產生的程式碼 "

''''此為 Web Form 設計工具所需的呼叫。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand
''''
''''SqlConnection1
''''
Me.SqlConnection1.ConnectionString = "workstation id=""MYCHAT-BDA1F78B"";packet size=4096;integrated security=SSPI;data s" & _
"ource=""MYCHAT-BDA1F78B"";persist security info=False;initial catalog=ggg"
''''
''''SqlCommand1
''''
Me.SqlCommand1.Connection = Me.SqlConnection1

End Sub
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

''''注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
''''請勿刪除或移動它。
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
''''CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
''''請勿使用程式碼編輯器進行修改。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''''在這裡放置使用者程式碼以初始化網頁

''''打開資料庫
SqlConnection1.Open()
''''執行SQL指令 ''''" & Request("time") & "''''

SqlCommand1.CommandText = "select Top 20 * from guestbook order by Time desc "

Dim dr As System.Data.SqlClient.SqlDataReader = SqlCommand1.ExecuteReader()





''''自由發揮
dr.Read()
If Not dr.Read() Then
Else


Response.Write("<h1> 訪 客 留 言 版</h1><br><hr>")
Response.Write("姓名:" & dr.Item("name") & "<BR>")
Response.Write("信箱:" & dr.Item("Email") & "<BR>")
Response.Write("標題:" & dr.Item("Subject") & "<BR>")
Response.Write("時間:" & dr.Item("Time") & "<BR>")
Response.Write("留言內容:")
dr.Close()
End If




''''關閉資料庫
SqlConnection1.Close()


End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim URL
URL = "Webform2.aspx"
Response.Redirect(URL)
End Sub
End Class


--------------------------------------------------------------------------------------------------------------
要送出留言的WebForm2
---------------------------------------------------------------------------------------------------------------


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''''在這裡放置使用者程式碼以初始化網頁
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Page.IsPostBack Then
'''' Dim objCon As SqlConnection
''''Dim objCmd As SqlCommand
Dim strSQL, strDbCon As String
Dim count As Integer
'''' Sql提供者字串
'''' strDbCon = "server=(local)\cmwupc;database=users;"
'''' 建立SQL敘述新增一筆資料表記錄
strSQL = "INSERT INTO MEMBER (name,subject,email,body) VALUES ( "
strSQL = strSQL & "''''" & Name.Text & "'''',"
strSQL = strSQL & "''''" & Subject.Text & "'''',"
strSQL = strSQL & "''''" & Email.Text & "'''',"
strSQL = strSQL & "''''" & Body.Text & "''''"
strSQL = strSQL & " ) "
'''' 建立Connection物件
''''SqlConnectionObj = New SqlConnection(strDbCon)
SqlConnection1.Open() '''' 開啟資料庫連結
'''' 建立Command物件的SQL指令
'''' SqlCommandObj = New SqlCommand(strSQL, objCon)
'''' 執行SQL指令
SqlCommand1.CommandText = strSQL
''''Label10.Text = strSQL
count = SqlCommand1.ExecuteNonQuery
SqlConnection1.Close() '''' 關閉資料庫連結

End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim URL
URL = "webform1.aspx"
Response.Redirect(URL)
End Sub
End Class

-----------------------------------------------------------------------------------------------------------------

請問...到底要怎麼樣才能 在顯示下面已留言的 WebForm1

拜託拜託拜託拜託!



這篇文章最後由 prund 在 2006/06/17 00:06:32 重新編輯。



瘦小腹 | 回到頂部

簡版






要要輸入新增留言的webForm1 + 下面是要顯示 已留言的留言內容
-------------------------------------------------------------------------------------------------

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form 設計工具產生的程式碼 "

''''此為 Web Form 設計工具所需的呼叫。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand
''''
''''SqlConnection1
''''
Me.SqlConnection1.ConnectionString = "workstation id=""MYCHAT-BDA1F78B"";packet size=4096;integrated security=SSPI;data s" & _
"ource=""MYCHAT-BDA1F78B"";persist security info=False;initial catalog=ggg"
''''
''''SqlCommand1
''''
Me.SqlCommand1.Connection = Me.SqlConnection1

End Sub
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

''''注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
''''請勿刪除或移動它。
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
''''CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
''''請勿使用程式碼編輯器進行修改。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''''在這裡放置使用者程式碼以初始化網頁

''''打開資料庫
SqlConnection1.Open()
''''執行SQL指令 ''''" & Request("time") & "''''

SqlCommand1.CommandText = "select Top 20 * from guestbook order by Time desc "

Dim dr As System.Data.SqlClient.SqlDataReader = SqlCommand1.ExecuteReader()





''''自由發揮
dr.Read()
If Not dr.Read() Then
Else


Response.Write("<h1> 訪 客 留 言 版</h1><br><hr>")
Response.Write("姓名:" & dr.Item("name") & "<BR>")
Response.Write("信箱:" & dr.Item("Email") & "<BR>")
Response.Write("標題:" & dr.Item("Subject") & "<BR>")
Response.Write("時間:" & dr.Item("Time") & "<BR>")
Response.Write("留言內容:")
dr.Close()
End If




''''關閉資料庫
SqlConnection1.Close()


End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim URL
URL = "Webform2.aspx"
Response.Redirect(URL)
End Sub
End Class


--------------------------------------------------------------------------------------------------------------
要送出留言的WebForm2
---------------------------------------------------------------------------------------------------------------


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''''在這裡放置使用者程式碼以初始化網頁
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Page.IsPostBack Then
'''' Dim objCon As SqlConnection
''''Dim objCmd As SqlCommand
Dim strSQL, strDbCon As String
Dim count As Integer
'''' Sql提供者字串
'''' strDbCon = "server=(local)\cmwupc;database=users;"
'''' 建立SQL敘述新增一筆資料表記錄
strSQL = "INSERT INTO MEMBER (name,subject,email,body) VALUES ( "
strSQL = strSQL & "''''" & Name.Text & "'''',"
strSQL = strSQL & "''''" & Subject.Text & "'''',"
strSQL = strSQL & "''''" & Email.Text & "'''',"
strSQL = strSQL & "''''" & Body.Text & "''''"
strSQL = strSQL & " ) "
'''' 建立Connection物件
''''SqlConnectionObj = New SqlConnection(strDbCon)
SqlConnection1.Open() '''' 開啟資料庫連結
'''' 建立Command物件的SQL指令
'''' SqlCommandObj = New SqlCommand(strSQL, objCon)
'''' 執行SQL指令
SqlCommand1.CommandText = strSQL
''''Label10.Text = strSQL
count = SqlCommand1.ExecuteNonQuery
SqlConnection1.Close() '''' 關閉資料庫連結

End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim URL
URL = "webform1.aspx"
Response.Redirect(URL)
End Sub
End Class

-----------------------------------------------------------------------------------------------------------------

請問...到底要怎麼樣才能 在顯示下面已留言的 WebForm1

拜託拜託拜託拜託!



這篇文章最後由 prund 在 2006/06/17 00:06:32 重新編輯。



Flash Player 12 | 回到頂部

簡版






你遇到的問題是什麼呢??
如果是顯示問題,你新增時的Table名稱和顯示時的Table名稱抓的不一樣



購物車 | 回到頂部
下一主題 上一主題