Results 1 to 10 of 10

Thread: datagrid fill problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    datagrid fill problem

    VB Code:
    1. Dim sqlselect As String = "select job.jobnum,job.company,job.product_a,job.storcount,job.tline,job.week " & _
    2.         "received.weight,received.boxnum,received.numberrecvd,received.comments,received.recdate,received.bay " & _
    3.         "FROM received RIGHT JOIN Job ON received.JobNum = Job.JOBNUM;"
    4.         da = New SqlCeDataAdapter(sqlselect, ceConn)
    5.         ds = New DataSet("Job")
    6.         da.Fill(ds)
    7.         DataGrid.DataSource = ds.Tables(0)
    it gives me errors at the last line. my guess is that it doesnt like my query. not that the sql syntax isnt good,but it doesnt want to bind it. what is the correct way to do this? also how do i filter those records by a certain criteria. what i really want to do is not have all those records viewable, but everything that matches the result of my input box.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: datagrid fill problem

    ok, what if I want to fill my grid with an sql view. can i do that? i think i found a c# example but i cant read it.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: datagrid fill problem

    if i have learn soem xml so be it. i just need some sort of direction. if you read my other posts you will see that i tried a datareader,databinding to textboxes and such. now i am running low on options.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: datagrid fill problem

    Well, if the error is on the last line, then the SQL has already worked fine. However, if you want to select rows based on values in a text box, you'll need a WHERE clause in there.

    The simplest way to do that would be adding

    "WHERE <somefield> = '" & textbox.text & "'"

    right after the FROM clause.

    Of course, it would be a bit safer to test the value in the text box to see that it is at least close to the right range, but if nothing is entered, or something bad is entered, you simply won't get any data.....unless something REALLY bad is entered, such as:

    ",DROP TABLE received"

    That would be malicious, because your table would be deleted.

    What is the error you are getting. The syntax you have looks mighty familiar. In fact, it looks like something I might have posted in response to an earlier question. If it is, then I know that it SHOULD work, because it works for me.
    My usual boring signature: Nothing

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: datagrid fill problem

    Aha, one critical difference.

    I read in a book that you need to do this:

    VB Code:
    1. dg1.Enabled = False
    2. dg1.DataSource = ds.Tables(0)
    3. dg1.Enabled = True

    The book mentioned that enabling and disabling the datagrid made it work right. I see that I have only done it that way, and otherwise am doing the same thing that you are. Try that.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: datagrid fill problem

    ok this is odd. when i have my posted code with your code in the load procedure it stops at dg.enabled=false and says it cant do that. i look at the highlted line and it says dg.enabled=true. but if i have our code triggered by another procedure i get a token line error, error parsing.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: datagrid fill problem

    ok i found my error. i was missing a comma at the end of my first line of my sql. hopefullly works now.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: datagrid fill problem

    hooray for me. oddly enough the same code doesnt work in the load but works by trigger.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: datagrid fill problem

    ok i was wrong, i forgot the connection part. i have my parameters working fine and i can search as much as i want. now how do i edit and update records? another thing, in my received table i hate a date field that i used to be able to autofill with todays date and time. this was when i used an "insert" sql command. am i still ognna be able to do that?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: datagrid fill problem

    i found a site that is written in c++, it looks like what i need. could someone translate into vb?
    http://www.wwwcoder.com/main/parenti...8/default.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width