Dans votre méthode Page_Load, exécutez votre requête. Sur votre page.aspx, vous avez un contrôle de formulaire, appelons-le label1. Définissez label1.text = queryResult.
Sub Page_Load()
dim myConnection as new data.sqlclient.sqlconnection
dim myCommand as new data.sqlclient.sqlcommand
dim sqlReader as data.sqlclient.sqldatareader
myConnection.connectionString = 'enter your connection string details'
myConnection.Open()
myCommand = New SqlCommand("Select lastUpdated from yourTable", myConnection)
sqlReader = myCommand.ExecuteReader()
if sqlReader.hasRows then
sqlReader.read()
label1.text = Format("MM/dd/yyyy", sqlReader("lastUpdated"))
end if
End Sub
Et votre page.aspx (quelque part)
<asp:label id="Label1" runat="server" />
PS - je trompe peut-être la fonction de format ci-dessus, été pendant quelque temps.
EDIT basé sur Commentaire:
Eh bien, pour ce que vous faites, je ne recommanderais pas vraiment un SQLDataSource car il est vraiment destiné à être lié à un contrôle tel qu'un gridview ou répéteur. Toutefois, si vous voulez utiliser SQLDataSource, vous devrez vous lier à un DataView dans votre code-behind. De là, vous pouvez accéder à chaque ligne (vous ne devriez en avoir qu'un) et à la colonne par nom.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dv As New Data.DataView
'use the id of your SqlDataSource below'
dv = SqlDataSource1.Select(DataSourceSelectArguments.Empty)
Label1.Text = dv.Table.Rows(0)("LastUpdated")
End Sub
d'utiliser une chaîne de connexion du web.config:
web.config Fichier:
<appSettings>
<add key="strConnectionString" value="Data Source=192.168.0.55;Database=Times;User ID=sa;PassWord=sa"/>
</appSettings>
code Derrière:
Dim sqlConn as new data.sqlClient.SqlConnection()
sqlConn.ConnectionString=ConfigurationManager.ConnectionStrings("strConnectionString").ConnectionString
sqlConn.Open()
Si tout ce que vous voulez afficher est la dernière mise à jour (champ unique), puis aucun point utilisant DataGrid. Utilisez juste un DataReader ADO.NET, beaucoup d'exemples autour. Voici un: http://msdn.microsoft.com/en-us/library/haa3afyz.aspx – RPM1984