June 24, 2007 at 4:38 am
Hi all,
I have received a error :
Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
what does it mean? Here is my code by the way for reference.
**************************************************************
Imports system.data
Imports System.Data.SqlClient
Partial Class SupplierRecord
Inherits System.Web.UI.Page
Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim cmd As SqlCommand
Dim dt As DataTable
Private Sub reload()
dt = New DataTable()
da = New SqlDataAdapter("select * from dbo.product where ProductName= 'helmet'", conn)
da.Fill(dt)
GridView1.DataSource = dt
Session("dt") = dt
DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn = New SqlConnection("database=Wyler; server=.\sqlexpress; integrated security=true; user id=sa; password=password")
reload()
End Sub
**************************************************************
The error somehow points to the Databind()
What does the error msg mean?
Thanks!
June 24, 2007 at 6:16 am
Check your connection string; how this could be: integrated security=true means win authentication and still you use sql authentications with sa as loginid; what is the error body and number actually?
June 24, 2007 at 10:47 pm
What michael says is right. You can't have integrated scuirty parameter true and use the uder id and password combination. If you find difficult building your connection string build a udl file and use the connection string that you get from there.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
June 26, 2007 at 10:45 am
Aside from your connection string issues, this error is in all probability generated due the fact that in your Asp.Net code where you've got the Gridview defined, I would think that somewhere you've got a variation of this:
<asp:GridView ID="Gridview1" runat="server" DataSourceID="some_controlID" />.
Well, this would be fine except for the fact you're setting the datasource of the Gridview programmatically by this line in your displayed source code: Gridview1.DataSource = dt. The gridview's datasource can only be set by one of these methods on a particular page, but not both. Hope this helps.
June 26, 2007 at 8:42 pm
to Longv:
It works... you are right. I remove the one that is in my aspx code and create a new one using the visual basic.
tnx for all the help everyone!
November 27, 2008 at 11:31 pm
Hi,
I have got a very strange issue.
The application is built using VS 2008, SQL Server 2005
The connection string for my application is using windows authentication, ie
"Server=ComputerName;Database=DatabaseName;Trusted_Connection=yes;"
I have used a gridview control as follows,
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
Columns
asp:BoundField DataField="Column1" HeaderText="First Column" />
asp:BoundField DataField="Column2" HeaderText="Second Column" />
/Columns>
/asp:GridView>
Code behind for the same as follows,
GridView1.DataSource = DataSet1; //DataSet1 contains the value
GridView1.DataBind();
I have created a virtual directory for the application in IIS.
Now when I run the application using ASP.NET development server it binds the value to gridview and output the perfect result, however when i try to run the application using IIS, it throws an exception as follows,
"Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition."
Its quite urgent, I will appreciate any quick response.:)
[Note: the editor used in this forum was not allowing the character '<', hence I deleted all those charcters from the aspx code mentioned above.]
Vidya...
November 28, 2008 at 1:55 am
Hi All,
I could solve the problem by creating a database in remote server, however I did not get an idea why it was failing when the database was on the same machine with windows authentication.
Vidya...
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy