SQL ????? ?? ??? ???? ?? ??? ???? ASP.NET ??? Visual Basic .NET ?? ????? ???? ???????? ???????????

???? ?????? ???? ??????
???? ID: 306574 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ???? ASP.NET ?? ADO.NET ?? ????? ???? ?? ??? ???? ????????? ???? ?? ?? Visual Basic .NET ?? ????? ?? ??? ?? Microsoft SQL ???????? ????? ?? ??? ???? ?? ??? ??? ????? ???????? ?? ?? ?????? ???????? ?? ??? ??????????

??? ????? ?? ???? ???? ???? ?? ???? ???????? ????????? ????? ??????? ??? ????? ??? ???????? ????????? ????? ???? ??, ?? ??? ?????? ?????? ????? ??? ?? ???? ?? ??? ???? ?? ??? ?? ???????? ???? ?? ?? ???? ???????? ????????? ????? ??, ?? ??? ???? ????????? ???? ??, ?? ?? ?????? ???????? ??? ??? ?? ??? ?? ????????? ?? ?????? ???

?? ???? ????????? ???? ?? ?? ?? ?????? ?????????? ?????? ???? ?? ?? ??? ??????? ????? ?? ??? ???? ?? ????????? ??? ??????? ??? ????? ???? ??:
  • ???? ??? ????? ??? ??? ?????????? ?????? ???? ???
  • ?? ???? ????? ???????? ?? ??? ?????? ????????? ???? ???
  • ??? ???? ???????? ?? ??? ?? ????????? ?? ?????? ????????? ???? ???
  • ??? ??? ???????? ?? ???????? ????????? ?? ??? ???? ??? ?? ??? ???? ?? ????? ???? ???

??????????

????? ???? ???????? ?????????, ?????????? ???? ??????? ???? ??, ??????? ???? ??????, ?? ?????? ????? ?????? ???:
  • Microsoft SQL Server 7.0 ?? ??? ?? ???????
  • Microsoft Visual Studio .NET
  • Microsoft Visual Basic .NET
  • ??? ???????? ????????? ?? ????? ?? ??? ????????? ???????
?? ???? ????? ?? ?? ?? ?????????? ?? ??? ?????? ??? ????:
  • SQL ????? ???????? ????????????

??? ASP.NET ????????? ????? ?? ???????? ??????

?? ?????? ??? ?? ??? ASP.NET ????????? ????? ?? ????? ??? ?????????? ???????? ??? ????? ??? ?? ?? ????? Microsoft Visual Basic .NET ?? ????? ???? ???? ????????? ????? ?? ???, ????? ????? ?? ???? ????:
  1. ???????????? ????, ??????????? ????? ????, Microsoft Visual Studio .NET?? ??? ????? ????, ?? ???? ??? Microsoft Visual Studio .NET.
  2. ??? ??????????? Visual Studio .NET ??????? ????? ??, ????? ?????
  3. ??? ????????? ????? ????? ???, ????????? ???????? ??????? Visual Basic ????????? ????? ????, ?? ???? ??? ASP.NET ??? ??????????????????? ??? ????? ?????
  4. ??? ????? ???, ???? ??? ????????? ?? ??? ??? ??? ?????, ?? ?? ???????? ?????
  5. ??? ??????? ?? ??? ????? ????? ???????? ??????, ?? ??? ???? ??? ?? ??? ??? ?? ???? ??? ???????? ???:
    ?? ?????? ?? ??????? ?????? ?????? ?? ??????? ????
    ???????????? ?????? ???
    ????lblLastName???? ?? ????? ??? ???? ????:
    ??? ?????txtLastName%
    ???btnGetAuthors???? ??????? ????
    ????lblRowCount(?????? ??????)

  6. ??? ??????? ?? ??? ?? ???? ????? ????? ???????? ????? ????? ?? ?????? ?? ??? ??? ???? ???? ?? ??? ??? ?? ???GrdAuthors.
  7. ????? ????-????? ????, ?? ??? ' ????? ?????? '????? ?????
  8. 1 ?????????? ????? ?? ??? ????? ????, ?? ?? ???????? ?????

GetAuthorsByLastName ????? ???????? ?????????

????? ?? ??? ????? Transact SQL ??? ?? ????? ???? GetAuthorsByLastName ???????? ?????????:
Create Procedure GetAuthorsByLastName1 (@au_lname varchar(40), @RowCount int output)  
as 

select * from authors where au_lname like @au_lname; 

/* @@ROWCOUNT returns the number of rows that are affected by the last statement. */ 
select @RowCount=@@ROWCOUNT
				
?? ??? ?? ???????? ????? ???: @au_lname ?? @RowCount. , @au_lname ???????? ??? ????? ???????? ?? ??? ??? ???????? ??????? ???? ?? "?? ???" ?????? ?????? ??? ?????? ??? ?????? ???????? ?? ????? ???? ?? @RowCount ???????? ?? ???????? ????????? ?? ??????? ???? ?? ??? @@ROWCOUNT ???

?????, ?? ???????? ????????? ?????

SQL Server ??????? ?? ??????? ?? ???, ???? System.Data.SqlClient ???????? ?? ?? ???????? SqlDataReader ???? ?? SqlDataAdapter ???????? ?????? ????? ??, ???? ???? ????? ?? SqlDataReader SQL Server ??????? ?? ????????? ?? ???-???? ??????? ?? ????? ?? ??? ????? ?? ???? ???? DataAdapter ???? ???? ?? ?? ??????? ??????? ?? ?? ??? ?? ???????????? ???? ?? ?? ?? ??????? ???????? ?? ???? ?? ??? ?? SQL Server ??????? ?? ?????? ???? ?? ??? ????? ?? ???? ????

ADO.NET ??????? ???????? ?? ???? ?? ??? ??????-resident ???????????? ??, ?? ????? ???? ?? ?? ?? ??????, ??????? ???????????? ???? ???? ???? ?????? ????? ??. ????? ??? ?? ?????? ??? ??? ??? ?? ?????????? ?? ????? ???? ???
  1. ??? ??????? ?? ??? ????? ?????
  2. ?? ????? ?????? ??? ????? ??? ?????? ???? ??? ????? ?? ????? ?? ????? ???? ?? ?? ??? ???????:
    Imports System.Data
    Imports System.Data.SqlClient
    					
  3. ????????? ???? ?? ???????? ????????? ????? ?? ?? ????? ?? ??? ??? ??? ???????? ?????????, ?? ????? ???? ??? SqlCommand ???????? ??? SqlDataReader ???????? ?? ???? ?? ??????? ?? ??????? ??? SQL ???? ?? ????? ?? ??? SqlCommand ?? ????? ?? ???? ???? ExecuteReader ???? ?????? ???? ?????? ?? ??? ??? ???? ????????? SqlDataReader, ???? ???? ?? ??? SqlCommand ?? ??? ??? ?????

    ?????? ??? ??????? ?? Page_Load ????? ??? ????? ???:
    'Only run this code the first time the page is loaded.
    'The code inside the IF statement is skipped when you resubmit the page.
    If Not IsPostBack Then
        Dim MyConnection As SqlConnection
        Dim MyCommand As SqlCommand
        Dim MyDataReader As SqlDataReader
    
        'Create a Connection object.
        MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")
    
        'Create a Command object, and then set the connection.
        'The following SQL statements check whether a GetAuthorsByLastName stored procedure 
        'already exists.
        MyCommand = New SqlCommand("if object_id('pubs..GetAuthorsByLastName') is not null " + "begin" + " if objectproperty(object_id('pubs..GetAuthorsByLastName'), 'IsProcedure')= 1" + " select object_id('pubs..GetAuthorsByLastName')" + " else" + " return " + "end" + " else" + " return", MyConnection)
    
        With MyCommand
            'Set the command type that you will run.
            .CommandType = CommandType.Text
    
            'Open the connection.
            .Connection.Open()
    
            'Run the SQL statement, and then get the returned rows to the DataReader.
            MyDataReader = .ExecuteReader()
    
            'If any rows are retuned, the stored procedure that you are trying 
            'to create already exists. Therefore, try to create the stored procedure
            'only if it does not exist.
            If Not MyDataReader.Read() Then
                .CommandText = "create procedure GetAuthorsByLastName (@au_lname varchar(40), " & _ 
    
                                "@RowCount int output) " & _ 
    
                                " as select * from authors where au_lname like @au_lname; select @RowCount=@@ROWCOUNT"
                MyDataReader.Close()
                .ExecuteNonQuery()
            Else
                MyDataReader.Close()
            End If
    
            .Dispose()  'Dispose of the Command object.
            MyConnection.Close() 'Close the connection.
        End With
    End If
    					
  4. BtnGetAuthors ??? ????? ???? ????? ??? ???????? ????????? ?? ??? ????, ?? ?? ???? ???????? ????????? ?? ????? ?? ??? SqlDataAdapter ???????? ?? ????? ????? ???????? ????? ???? ???????? ????????? ?? ??? ?? ??? SqlDataAdapter ???????? ?? ???????? ?????? ???? ?? ??? ???????

    ????? ??? ?????? Page_Load ????? ?? ???:
    Private Sub btnGetAuthors_Click(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles btnGetAuthors.Click
        Dim DS As DataSet
        Dim MyConnection As SqlConnection
        Dim MyDataAdapter As SqlDataAdapter
    
        'Create a connection to the SQL Server.
        MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")
    
        'Create a DataAdapter, and then provide the name of the stored procedure.
        MyDataAdapter = New SqlDataAdapter("GetAuthorsByLastName", MyConnection)
    
        'Set the command type as StoredProcedure.
        MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
    
        'Create and add a parameter to Parameters collection for the stored procedure.
        MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@au_lname", _
       SqlDbType.VarChar, 40))
    
        'Assign the search value to the parameter.
        MyDataAdapter.SelectCommand.Parameters("@au_lname").Value = Trim(txtLastName.Text)
    
        'Create and add an output parameter to Parameters collection. 
        MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@RowCount", _
        SqlDbType.Int, 4))
    
        'Set the direction for the parameter. This parameter returns the Rows returned.
        MyDataAdapter.SelectCommand.Parameters("@RowCount").Direction = ParameterDirection.Output
    
        DS = New DataSet() 'Create a new DataSet to hold the records.
        MyDataAdapter.Fill(DS, "AuthorsByLastName") 'Fill the DataSet with the rows returned.
    
        'Get the number of rows returned, and then assign it to the Label control.
        'lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"
        lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters(1).Value & " Rows Found!"
    
        'Set the data source for the DataGrid as the DataSet that holds the rows.
        Grdauthors.DataSource = DS.Tables("AuthorsByLastName").DefaultView
    
        'Bind the DataSet to the DataGrid. 
        'NOTE: If you do not call this method, the DataGrid is not displayed!
        Grdauthors.DataBind()
    
        MyDataAdapter.Dispose() 'Dispose of the DataAdapter.
        MyConnection.Close() 'Close the connection.
    End Sub
    					
  5. ?????? Explorer ???,. aspx ?????, ????-????? ???? ?? ??? ????? ???? ??????? ????? ?? ??? ??? ??? ????.
  6. ????????? ??????, ?? ???? ??? Visual Studio .NET ??? ??????? ???? ????? ????? ????? ??? ?? ????????? ?????? ?? ?? ???????? ????? ?? ????? ???
  7. ???? ?? ????? ??? ??? ????? ??? ???? ????, ?? ???? ??? ????? ???? ???? ??????? ????? ????? ???????? ????????? ??? ???? ???? ?? ?? ?? ??? ?? ????????? ???? ??????????

    ?? ???? ??? ?????????? SQL Server-?????? ?????? ?? ???? ???.G %, ?? ??? ?????? ?????? ????? ???? ?? ????? ??? ????? "G." ?? ??? ??????? ????

?????? ??????

  • ?? ??????? ?? ?????? ???? ?? ????, ?? ?? ????????? ???? ?? ?? ConnectionString ??? ?? SQL ??? ??? ?? ?? ????? ?? ????? ???? ??????
  • ??? ?? ??????? ?? ?????? ?? ???? ???, ????? ?? ????? ???? ??? ?? ???????? ????????? ?? ????? ?? ??? ?? ?????? ???? ??? ???????? ????????? ???? ?? ???? ??? ?? ???? ?? ??? ?? ??????? ??? ???????? ???????????? ????? ?? ??? ??? ????????? ?? ?????? ?? ??? ????

??????

???? ??????? ?? ??? ??? ????? ???? ????? Microsoft .NET Framework ?????????? ????????? ??? (SDK) ?????????:
ADO.NET ?? ????????? ??????
http://msdn.microsoft.com/en-us/library/h43ks021.aspx

ADO.NET ???????
http://msdn.microsoft.com/en-us/library/zb0sdh0b (VS.71). aspx

???? ?? ??????? ?? ??? .NET ???? ??????? ?? ????? ????
http://msdn2.microsoft.com/en-us/library/s7ee2dwt (vs.71). aspx
???? ??????? ?? ???, ????? ???????? ?????:
Wyke, ??? R., ?? Sultan Rehman ?? Brad Leupen. XML ???????????? (??? ??????). Microsoft ?????, 2001?
???? ??????? ?? ???, ????? Microsoft ????????? ????? & ?????????? ?????????:
ADO.NET ?? ??? 2389 ????????????
?? ??? ???????? Microsoft ?????? ????? ?? ????? ?? ?? ????? ?? ???? ?? ???, ???? ?? ???? ??? ??????? ????? ??, Microsoft ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ???? ????? ???:
300488 SQL ?? ????? ?? ??? ???? ???????? ????????? ?? ASP ??? ??

???

???? ID: 306574 - ????? ???????: 30 ?? 2013 - ??????: 5.0
???? ???? ???? ??:
  • Microsoft ASP.NET 1.0
  • Microsoft ASP.NET 1.1
  • Microsoft ADO.NET 1.1
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
??????: 
kbhowtomaster kbsqlclient kbsystemdata kbmt KB306574 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:306574

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com