ASP.Net/ADO.net Database/SQL Direct — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:30, 26 мая 2010

Use direct SQL to insert data to database in VB

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
  Sub Page_Load(Sender As Object, E As EventArgs)
    Dim objConnection As OleDbConnection
    Dim objCmd        As OleDbCommand
    Dim strConnection As String
    Dim strSQL        As String
    
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source="+MapPath("EmployeeDatabase.mdb")
  
    objConnection = New OleDbConnection(strConnection)
    objConnection.Open()
    
    strSQL = "INSERT INTO Employee(FirstName,LastName)" & _
                      " VALUES ( "Beth" , "Hart" )"
    objCmd = New OleDbCommand(strSQL, objConnection)
    
    objCmd.ExecuteNonQuery()
    lblStatus.Text = "Command run"
  End Sub
</script>
<html>
  <body>
    <h2>Using SQL directly</h2>
    <asp:Label id="lblStatus" runat="server"/>
  </body>
</html>


<A href="http://www.nfex.ru/Code/ASPDownload/EmployeeDatabase.zip">EmployeeDatabase.zip( 10 k)</a>