DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Datagrid problem again!

  1. #1
    Join Date
    Aug 2005
    Posts
    111

    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.

  2. #2
    Join Date
    Dec 2004
    Posts
    717
    I think it's not datagrid problem...
    Have u checked ds.Table(0).Rows.Count?
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  3. #3
    Join Date
    Aug 2005
    Posts
    111
    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.

  4. #4
    Join Date
    Dec 2004
    Posts
    717
    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.
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  5. #5
    Join Date
    Aug 2005
    Posts
    111
    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

  1. DataGrid Postback problem
    By mrwassermann in forum ASP.NET
    Replies: 3
    Last Post: 04-18-2005, 06:16 PM
  2. A problem of locating a row in Datagrid
    By Anu in forum VB Classic
    Replies: 0
    Last Post: 01-16-2003, 06:42 AM
  3. Reliability Problem
    By elise in forum Java
    Replies: 0
    Last Post: 10-30-2002, 05:40 AM
  4. ADO DataGrid problem
    By christof Laeremans in forum VB Classic
    Replies: 0
    Last Post: 10-23-2001, 03:22 PM
  5. VB6 ADO DataGrid cell edit problem
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center