Please help. Required in a very short time to break up with the technology of ASP and Microsoft SQL.

Microsoft SQL Server 2008 and Visual Studio 2010 are available. Give an example of connecting to the database and retrieving data from it. And, if there is, a reference to the splints.

FOR THE MOST SMART: In Googl'e already been.

    1 answer 1

    In web.config :

     <configuration> <connectionStrings> <add name="connectionString1" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\db1.mdf;User Instance=true" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration> 

    VB.NET code:

     Dim myConnStr As String = ConfigurationManager.ConnectionStrings("connectionString1").ConnectionString Dim cnn As New SqlConnection(myConnStr) Dim selectCommand As New SqlCommand("SELECT * from table1 WHERE p1=@p1Value and p2=@p2Value", cnn) selectCommand.Parameters.Add(New SqlParameter("@p1Value", _ SqlDbType.SmallInt)).Value = CType(100, Integer) 'установка значения типа соотв. в БД selectCommand.Parameters.Add(New SqlParameter("@p2Value", _ SqlDbType.Real)).Value = CType(10.5, Double) cnn.Open() Dim dataReader As SqlDataReader dataReader = selectCommand.ExecuteReader(CommandBehavior.CloseConnection) If dataReader.HasRows Then Try Dim i As Integer = 0 While dataReader.Read 'dataReader.Item(j) 'очередная строка, Item(j) - j номер столбца, можно обращаться по имени столбца i += 1 End While Catch ex As Exception End Try Else End If dataReader.Close() cnn.Close() 

    There may be syntax errors.