-
Datagrid problem again!
Hi,
I work on a datagrid for almost half day, but still could not find out the problem:
There is a dataadapter DA which contains a SELECT statement with parameters. DA also generates a dataset DS. Then, I put a datagrid DG in a web forms and in the properties item Datasource, I bind it to DS. I preview data in DA and giving it all values to its parameters. Data could be retrieved. In the Page_Load event of code-behind page, I write:
Dim newDA as new sqldataadapter(DA.selectcommand.commandtext, conn)
conn.open()
newDA.selectcommand.parameters.add("@name", sqldbtype.varchar, 60).value = "'%'"
newDA.fill(DS)
DG.databind()
I run this page, but no row is retrieved, why???!!!. The SELECT statement is:
SELECT custname, custID FROM customer WHERE custname LIKE @name
Thank you very much.
-
I think it's not datagrid problem...
Have u checked ds.Table(0).Rows.Count?
-
Thank Sync,
I have checked the ds.tables(0).rows.count and it is equal to zero. That is the problem because when I try to work on the DA, it returns all rows that I needed. However, when I define another dataadapter in the code-behind page as mentioned above, it doesn't return anything!!!
So, would you have any other idea? Thank you.
-
I have checked as u're saying.. It's fine..
Dim da As New SqlDataAdapter
Dim dbConn As New SqlConnection
Dim ds As New DataSet
dbConn.ConnectionString = strConnectionString
dbConn.Open()
da.SelectCommand = New SqlCommand("SELECT eID,eName,eAddress FROM PInfo WHERE eAddress LIKE @varTitle", dbConn)
da.SelectCommand.Parameters.Add("@varTitle", SqlDbType.VarChar, 60).Value = "%"
da.Fill(ds, "PInfo")
Console.WriteLine("Row Count : " & ds.Tables(0).Rows.Count.ToString)
Dim newDA As New SqlDataAdapter(da.SelectCommand.CommandText, dbConn)
newDA.SelectCommand.Parameters.Add("@varTitle", SqlDbType.VarChar, 60).Value = "%"
Dim ds1 As New DataSet
newDA.Fill(ds1)
Console.WriteLine("Row Count : " & ds1.Tables(0).Rows.Count.ToString)
Last edited by Sync; 08-26-2005 at 09:12 AM.
-
Thank you very much, Sync
Your example really help me so much, and finally, I find out that the possible reason that the DA returns zero is .NET does not allow me to define a new dataadapter which is instantiated with the SQL statement of another dataadapter. That means, I have to use the original one in order to bind with the dataset and datagrid.
I could not verify if this is the actual cause, but the problem is solved.
Similar Threads
-
By mrwassermann in forum ASP.NET
Replies: 3
Last Post: 04-18-2005, 06:16 PM
-
By Anu in forum VB Classic
Replies: 0
Last Post: 01-16-2003, 06:42 AM
-
Replies: 0
Last Post: 10-30-2002, 05:40 AM
-
By christof Laeremans in forum VB Classic
Replies: 0
Last Post: 10-23-2001, 03:22 PM
-
By Brenton Norman in forum VB Classic
Replies: 0
Last Post: 04-10-2001, 01:13 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|