Recent Posts

ASP.NET: Ví dụ cơ bản về lập trình kết nối cơ sở dữ liệu

-

<html>
<head>
<script language="vb" runat="server"> 
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim stringConnectionString As String
Dim stringSql As String
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim objDataReader As OleDbDataReader
Dim i As Integer
Dim sTemp As String
Dim stringMapPath As String
stringConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
stringMapPath = Server.MapPath("sampledb.mdb")
stringConnectionString = stringConnectionString & stringMapPath
objConnection = New System.Data.OleDb.OleDbConnection(stringConnectionString)
objConnection.Open()
stringSql = "SELECT * FROM tblSample"
objCommand = New System.Data.OleDb.OleDbCommand(stringSql, objConnection)
objDataReader = objCommand.ExecuteReader()
Response.Write("<table border=1 cellpadding=1 cellspacing=1>")
Do While objDataReader.Read
Response.Write("<tr>")
Response.Write("<td>" & objDataReader.Item("url") & "</td>")
Response.Write("<td>" & objDataReader.Item("desc") & "</td>")
Loop
Response.Write("</table><br><br>")
objDataReader.Close()
objConnection.Close()
End Sub

</script>
</head>




Klik untuk melihat kode: :) =( :s :D :-D ^:D ^o^ 7:( :Q :p T_T @@, :-a :W *fck* x@