Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SqlDataSource and DataReaders
Message
From
03/06/2008 11:35:51
 
 
To
03/06/2008 00:52:39
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01319299
Message ID:
01321320
Views:
21
Thanks Bonnie. You are right on! My problem was not the connection string at all but was the use of SQLClient instead of the OLEDBClient. I'm using the new 2008 Express Web Developer.
Thanks

>I guess I should assume that you're using VS 2005 (the config stuff was handled a little bit differently in VS 2003). You'll need to change the code you posted below to use the OleDB objects rather than the Sql objects if you're using VFP (Don't quote me on the exact syntax for the connection string ... but it's at least similar to this).
>
>
><configuration>
>  <connectionStrings>
>    <add name="MyConnStr" connectionString="Provider=vfpoledb.1;Data Source=c:\MyDataBaseDir\;Collating Sequence=general" />
>  </connectionStrings>
></configuration>
>
>
>
>And to get that configuration string in your app:
>
>
>// you need a using also:
>using System.Configuration
>
>string cConnection = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;
>
>
>~~Bonnie
>
>
>
>>Thanks Perry. With the help of intellisense I have continued your sample as follows
>>    Public Sub ReadUsers()
>>        Dim sql As String = "select * from users"
>>        Dim connString As ConnectionStringSettings
>>
>>        ' Create connection
>>        Dim conn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(connString)
>>
>>
>>        Try
>>            ' Open connection
>>            conn.Open()
>>
>>            ' Create command
>>            Dim cmd As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand(sql, conn)
>>
>>            ' Create data reader
>>            Dim rdr As Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
>>
>>            ' Loop through result set
>>            While rdr.Read
>>                Console.WriteLine("" & rdr(0))
>>            End While
>>            ' Close data reader
>>            rdr.Close()
>>        Catch
>>            MsgBox("Fail")
>>        End Try
>>
>>    End Sub
>>
>>Can you tell me how to define connString assuming the string is stored in webconfig as "MyConnStr" and is using VFPOLEDB?
>>Thanks
>>
>>
>>>Here's an incomplete code section, but should be enough for what you're looking for:
>>>
>>>
>>>Dim sql As String = "select contactname from customers
>>>
>>>' Create connection
>>>Dim conn As SqlConnection = New SqlConnection(connString)
>>>
>>>Try
>>>  ' Open connection
>>>  conn.Open()
>>>
>>>  ' Create command
>>>  Dim cmd As SqlCommand = New SqlCommand(sql, conn)
>>>
>>>  ' Create data reader
>>>  Dim rdr As SqlDataReader = cmd.ExecuteReader()
>>>
>>>  ' Loop through result set
>>>  While rdr.Read
>>>    Console.WriteLine("" & rdr(0))
>>>  End While
>>>  ' Close data reader
>>>  rdr.Close()
>>>
>>>
>>>
>>>
>>>>I am trying to figure out how to review the records retrieved with a SqlDataSource in code without using a display control. My research thus far suggests this can be done via a DataReader but I am unable to figure it out. If the datasource is SqlDataSource1 and it is configured to return a DataReader, can someone show me how to get at the records with VB? Something like:
>>>>
>>>><<pseudo code>>
>>>>dim oReader as Data.SQLClient.SQLDataReader = SqlDataSource1.DataReader
>>>>
>>>> While oReader.Read()
>>>>    Console.WriteLine(String.Format("{0}, {1}", oReader(0), oReader(1)))
>>>> End While
>>>>
>>>>
>>>>Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform