Variables inside SqlDataSource.SelectCommand

26 Feb

This way of working with sqlDatasource is very versatile a let you create a lot of handy stuff.

Ref:http://www.maconstateit.net/tutorials/aspnet20/ASPNET13/aspnet13-03.aspx

My Example:

I need to let the users select from two calendars control the ranges of dates they want to get from database.

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim begin_date As String = “”
begin_date = Calendar1.SelectedDate.ToString
TextBox3.Text = begin_date
End Sub

Protected Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar2.SelectionChanged
Dim end_date As String = “”
end_date = Calendar2.SelectedDate.ToString
TextBox4.Text = end_date
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlString As String = “Select [id],[x],[y], [cat_name], [zone_id], [name], [addr], [town], [phone], [webpage], [description], [town], [image_1], [fecha] From [ptg_events] where fecha between ‘” & TextBox3.Text & “‘ and ‘” & TextBox4.Text & “‘”
SqlDataSource1.SelectCommand = sqlString
SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.Text

GridView1.DataBind()

End Sub

SqlDataSource1.SelectCommand = sqlString
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: