hi
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
        Try
            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........

Recommended Answers

All 2 Replies

Hi there

Just try this after GridView1.datasource line

GridView1.DataBind()

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.