i had got a problem that
i want to display the difference between two dates to be displayed in a grid view ,here the first date can be taken from a textbox.
when the button is clicked the difference between dates to be displyed in days,
here iam using the sql query as

SELECT     DATEDIFF(dd, date_of_arr, date_of_dept) AS DAYS
FROM         guesthouse
WHERE     (date_of_arr = '"  & arrivaldate.text & "')

and the button click event code is as below

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connstr As String
        connstr = ConfigurationManager.ConnectionStrings("guest1").ConnectionString()
        Dim conn As New SqlConnection(connstr)
        Dim ds As New DataSet
        Dim da As SqlDataAdapter
            da = New SqlDataAdapter("select datediff(dd,date_of_arr,date_of_dept) from guesthouse where date_of_arr='" & arrivaldate.Text & "'", conn)
            da.Fill(ds, "questhouse")
            GridView1.DataSource = ds
        Catch ex As Exception
        End Try
    End Sub

but the code is not properly working
here button click event is not working.....
it automaticalyy shows dys but doesnot working the where condition.....
here the error is getting as
"Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition."
pls give me the answer........

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

8 Years
Discussion Span
Last Post by sknake

Hi there

Just try this after GridView1.datasource line


Remove the property GridView1.datasource at design time if any.

good luck
Pls. Mark as solved if it works!!!

Edited by reach_yousuf: n/a


You should also take note that in the SQL query you posted you named the column "Days" but in the click event you're not assigning a column name:

SELECT     DATEDIFF(dd, date_of_arr, date_of_dept) AS DAYS

Code (missing column name):

da = New SqlDataAdapter("select datediff(dd,date_of_arr,date_of_dept) from guesthouse

It is likely that value is not showing up in the expected column in your dataset.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.