Page 1 of 2 12 LastLast
Results 1 to 40 of 53

Thread: [RESOLVED] All I need to do is populate my form....

  1. #1

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Resolved [RESOLVED] All I need to do is populate my form....

    OK, so I've read http://www.vbforums.com/showthread.php?t=469872 15 times trying to find the answers. I have modified the code, and have come to the conclusion that I'm stumped.

    I have a form in VB 2005 with a number of fields:

    PhoneNumber
    Name
    Address
    CustomerID
    etc.

    Which correspond to the fields in my backend Access 2003 Database
    Cust_PhNumber
    Cust_Name
    Cust_Address
    Cust_ID
    etc.

    I can do the Insert into my Database no problem. What I'm trying to do is the user will put in a CustomerID in the VB form, and the rest of the data will then populate on the form; it can either be updated, deleted, or left alone. When the user hits the save button, it will update the database acccordingly.

    As I mentioned, jmcilhinney's post is really good, so I'm sure the Update portion will not be a problem (although my confidence is definitely wavering). I think a DataGrid would have been easier, but at the time I was designing the forms in Visio, it didn't make sense to have a datagrid that's going to be one row and 32 columns wide.

    Any ideas?? Appreciate your suggestions...
    Thanks
    Chris
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  2. #2
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    So basically what you want to do is return a result set based upon the ID your user enters?

    You need to write a select query that brings back the results you want, populate a dataset with those results, write a for loop to go through the dataset and populate your controls with the data.

  3. #3
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    try something like this
    vb Code:
    1. Dim sqlDA as New SqlDataAdapter
    2. Dim DS as New DataSet
    3. Dim SelectCmd as New SqlCommand
    4.  
    5. SelectCmd.CommandText = "SELECT Cust_PhNumber, Cust_Name, Cust_Address, Cust_ID FROM CustTable WHERE CustID = @CustID" ''obviously change cust table to whatever table you're using
    6. SqlDA.SelectCommand = SelectCmd
    7. SqlDa.SelectCommand.Connection = *Whatever you're using for a sqlConnection*
    8. SqlDa.SelectCommand.Parameters.Clear()
    9. SqlDa.SelectCommand.Parameters.AddWithValue("@CustID", txtcustid.text) ''insert the control you're using to grab the custid for txtcustid.text
    10.  
    11. SqlDa.fill(DS)
    12.  
    13. For Each Row As DataRow in DS.tables(0).rows
    14. txtname.text = Row("Name")
    15. txtaddress.text = Row("Address")
    16. etc
    17. Next

    one way to do it anyhow.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: All I need to do is populate my form....

    As you can see from BackWoodsCoder's example, using a parameter in a SELECT statement is exactly the same as using a parameter in a DELETE, INSERT or UPDATE statement. In fact, using parameters is ALWAYS the same regardless of the contents of the SQL code you're executing. The first five examples in my thread show you how to retrieve data and the sixth example shows you how to use parameters. I guess I just assumed that people would put the two together but you're far from the first to not, so maybe I'll add another example that does just that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hi Backwoodscoder and everyone else,

    OK, so I have taken the code as suggested by Backwoodscoder and have modified it with my info; i've also changed the Connection String to be consistent with the rest of the application.

    I realise this is a fairly straightforward piece of code, and I'm kind of smart, but I cannot figure out why nothing happens. I don't get any errors generated, but I put my CustomerID in the text field, hit tab, and....nothing.

    Any ideas? I read an online blog saying you need to use ExecuteDataReader but I don't know if that's required here........
    Appreciate your thoughts...
    Thanks
    Chris

    Private Sub Srv_CGITicket_LostFocusHandler(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim sqlDA As New SqlClient.SqlDataAdapter
    Dim DS As New DataSet
    Dim SelectCmd As New SqlClient.SqlCommand

    SelectCmd.CommandText = "SELECT Cust_name,Cust_PhoneNumber FROM Cust_Info WHERE CustID = @CustomerID"
    sqlDA.SelectCommand = SelectCmd
    Using connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\...\CustomerUtility.mdb")
    sqlDA.SelectCommand.Parameters.Clear()
    sqlDA.SelectCommand.Parameters.AddWithValue("@CustomerID", CustomerID.Text)
    sqlDA.Fill(DS)
    For Each Row As DataRow In DS.Tables(0).Rows
    Me.Srv_DateTimePicker1.Text = Row("Cust_Name")
    Me.Srv_Details.Text = Row("Cust_PhoneNumber")
    Next
    End Using
    End Sub
    End Class
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    Have you actually put a breakpoint in your code and verified that any of it is even being run at all?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    ......not entirely sure why I didn't think of that...

    No, in fact my code is not running at all. Now I'm really confused. Any way I can download VB2005 into my brain so I can stop pestering you nice people? :-)
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  8. #8
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    How did you hook up the event handler? I notice it doesnt have the Handles XXXX.LostFocus after it so I'm assuming you have used AddHandler somewhere?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  9. #9

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    hee hee hee ummmmmm I'm guessing this shows my total lack of experience with VB2005. No, i did not have the Handles portion of my Sub. Didn't even see that I had missed it, so thank you for showing me that.

    OK, so now at least my code is doing something - and then it stops. I'm now getting an error at the row "SQLDA.Fill(DS)".

    Error is "{"Fill: SelectCommand.Connection property has not been initialized."}"

    I've tried moving the SelectCmd.CommandText after the connectionString, but still get the same error.
    Appreciate your time...
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  10. #10
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    hee hee hee ummmmmm I'm guessing this shows my total lack of experience with VB2005. No, i did not have the Handles portion of my Sub. Didn't even see that I had missed it, so thank you for showing me that.
    One easy way to avoid mistakes like that is to let Visual Studio do it for you. When you are in code view, if you look at the drop down boxes at the top of the code page you should see one on the left that lets you pick an object/control and one of the right that shows you all of the events that the control you selected in the left drop down box has. If you select one of these events then VS will create the event handler for you

    As for your error, it is because as the error says - you have not set the Connection property. So simply tell it that you want it to use the OledbConnection object that you created like so:
    vb Code:
    1. SelectCmd.Connection = connection

    One thing I have just noticed though is that you are mixing the SQLClient and OleDb classes together - I dont know if that will work. I've only ever used the SQLClient classes myself but I assume there is an OleDb equivalent of SqlCommand and SqlDataAdapter etc that you should be using if you are working with Access
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    OK, this is all starting to make sense. Thanks Chris128 for your time.

    Now, back to my issue

    I've updated the SQL stuff to OleDB. There are comparitive selections for the OleDB as there were for the SQL, so changing them was not a big deal.

    When I updated my code and rearranged the order slightly (I was getting an error for Connection that said I was using it before it was established), my new code looks like this:

    [quote]
    Using connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\...\..\.mdb")
    SelectCmd.Connection = connection
    SelectCmd.CommandText = "SELECT ......"
    DA.SelectCommand = SelectCmd
    DA.SelectCommand.Parameters.Clear()
    DA.SelectCommand.Parameters.AddWithValue("@CustID", CustomerID)
    DA.Fill(DS)
    For Each Row As DataRow In DS.Tables(0).Rows
    Me.Srv_DateTimePicker1.Text = Row("Cust_PhoneNumber")
    Me.Srv_Details.Text = Row("Cust_Address")
    Me.Srv_Details.Text = Row("Cust_Details")
    Next
    End Using
    [\quote]

    I get a "Variable 'Connection' hides a variable in an Enclosing block" for the "Using connection..." statement. So I comment out the "Using connection..." and the "End Using", and the application runs, seems to query the data, but then it stops at the row Da.Fill(DS), with the error "{"Fill: SelectCommand.Connection property has not been initialized."}" once again. I'm also noticing now that my SelectCMD.Connection = connection has generated a warning, saying "Variable 'connection' is used before it has been assigned a value..." which makes sense as I haven't specified a Connection string. So, I am assuming the "Using..End Using" is the way to go, I just cannot figure out how to correct the error.
    Why is it I had less problems with Inserting than I do with a simple Select??? Argh....
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  12. #12
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    Using blocks are nice I suppose, but have you tried just Dim'ming out the connection as an object?

    Code:
     Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\...\..\.mdb")

  13. #13

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hey BackWoodsCoder,

    Only reason I did it that way is because that's how jmcilhinney's thread did it, and I'm not nearly experienced enough to "see" other ways of doing it...

    That being said, I've now tried your idea and am still getting an error on the DA.Fill(DS) row, "{"No value given for one or more required parameters."}".

    I'm reading through my code (all 15 lines of it LOL) very carefully, and I'm really hoping to catch this error myself. Ideas of course would be appreciated.....
    Chris
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  14. #14
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    Only reason I did it that way is because that's how jmcilhinney's thread did it, and I'm not nearly experienced enough to "see" other ways of doing it...
    All the "Using" block does is takes care of releasing any resources that your object may have been using. So doing this:
    vb Code:
    1. Using connection As New OleDbConnection("etc etc")
    2.        'use the connection object here
    3.        '....
    4. End Using
    is the same as doing this:
    vb Code:
    1. Dim connection As New OleDbConnection("etc etc")
    2. 'use the connection object here
    3. '....
    4. connection.Dispose

    As for your current error, can you post your actual Select statement?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  15. #15
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    Code:
    DA.SelectCommand.Parameters.AddWithValue("@CustID", CustomerID)
    put a breakpoint on that line, hover your mouse or use the immediate window to find out what value CustomerID is. I'm guessing this is where your problem is coming from.

  16. #16

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hi Chris128,

    Here's the actual select statement; the Customer Info was used to keep the issue generic, but I suppose I could have done it this way with the same effect.

    [code] SelectCmd.CommandText = "SELECT reported_user, reported_Support, outage_details FROM tOutagesServer WHERE Srv_Ticket = @Srv_Ticket"[\code]

    The columns in the Select are from my database, the tOutagesServer is my Access table name, and the Srv_Ticket is the text box name on my form.
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  17. #17

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Quote Originally Posted by BackWoodsCoder View Post
    Code:
    DA.SelectCommand.Parameters.AddWithValue("@CustID", CustomerID)
    put a breakpoint on that line, hover your mouse or use the immediate window to find out what value CustomerID is. I'm guessing this is where your problem is coming from.
    Just tried that, it's passing the correct information....I step through and then the next line, DA.Fill(DS) kicks out the error....
    Thanks
    Chris
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  18. #18
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    and you are sure that in your real code it looks EXACTLY like this (the only difference being that the DATA_HERE would be something else obviously:
    vb Code:
    1. DA.SelectCommand.Parameters.AddWithValue("@Srv_Ticket", DATA_HERE)

    Oh and you can also try adding the parameters in a different way, something like this:

    vb Code:
    1. DA.SelectCommand.Parameters.Add("@Srv_Ticket", OLEDB_DATA_TYPE_HERE).Value = DATA_HERE
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  19. #19

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hi Chris128,

    Yup, absolutely the same - DA.SelectCommand.Parameters.AddWithValue("@Srv_Ticket", Srv_Ticket.Text). I've also tried your second suggestion, and once again it's passing my parameter but getting stuck on the DA.Fill(DS) line.
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  20. #20
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    just for grins...

    Code:
    DA.SelectCommand.Parameters.Clear()
    comment out that line and run the code and see what happens.

  21. #21
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    is it still saying the exact same thing in the error message? No value given for one or more required parameters
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  22. #22

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hi BackWoodsCoder / Chris128,

    I commented out the .Parameters.Clear() line, and am still getting the error; and yup, it's definitely No Value Given for one or more required Parameters...

    Is it me or is this getting annoying and frustrating?
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  23. #23
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    Can you post your entire method again but exactly as it is now, only changing things that would affect security (e.g usernames and passwords in the connection string)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  24. #24

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hi chris128,

    Here you go...

    Private Sub Srv_Ticket_LostFocusHandler(ByVal sender As Object, ByVal e As System.EventArgs) Handles Srv_Ticket.LostFocus
    Dim DA As New OleDb.OleDbDataAdapter
    Dim DS As New DataSet
    Dim SelectCmd As New OleDb.OleDbCommand
    Dim connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\....\Notifications.mdb")
    SelectCmd.Connection = connection
    SelectCmd.CommandText = "SELECT reported_user, reported_support, outage_details FROM tOutagesServer WHERE Srv_Ticket = @Srv_Ticket"
    DA.SelectCommand = SelectCmd
    DA.SelectCommand.Parameters.Clear()
    DA.SelectCommand.Parameters.AddWithValue("@Srv_Ticket", Srv_Ticket.Text)
    DA.Fill(DS)
    For Each Row As DataRow In DS.Tables(0).Rows
    Me.Srv_User.Checked = Row("Reported_User")
    Me.Srv_Support.Checked = Row("Reported_Support")
    Me.Srv_Details.Text = Row("Outage_Details")
    Next
    End Sub
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  25. #25
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    Ok, let's do a little breakpoint investigation using your immediate window.

    Code:
    DA.Fill(DS)
    put a break point on that line, execute your code, when your program breaks go to the immediate window and type in the following

    Code:
    ?DA.SelectCommand.Parameters.Count
    Then look at the count, if the count is greater then 1 somehow somewhere another parameter is being added to the query. If it is one, go back to the immediate window and type in

    Code:
    ?DA.SelectCommand.Parameters(0).Value
    this will tell you the value the parameter is holding. If it is nothing there's your problem, if not it lies somewhere else.

  26. #26
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    I'm stumped!
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  27. #27

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hi BackwoodsCoder,

    this is what the immediate window's returning

    "123455" {String}
    String: "123455"

    123455 is the parameter I'm passing.
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  28. #28

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Quote Originally Posted by chris128 View Post
    I'm stumped!

    Crap. This doesn't bode well for me then LOL.

    Thanks for your time Chris128, it's very much appreciated. Any other ideas are more than welcome...
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  29. #29
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    What about when you do the ?DA.SelectCommand.Parameters.Count in the immediate window, what did that show?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  30. #30
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    So I'm assuming the count of your parameter collection was only one?

    This should not matter at all, but if your datatype for Srv_Ticket in your DB is int, and you're passing in a string, it may not like it.

    So, modify this line to read like this.

    Code:
    DA.SelectCommand.Parameters.AddWithValue("@Srv_Ticket", CInt(Srv_Ticket.Text))
    This will convert the string into an integer, it really shouldn't matter but it's worth a shot.

  31. #31

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Hi BackWoodsCoder,

    yes, a 1 was returned in the immediate window....should have clarified that...

    I've just double checked my database and the field is "text". would that make a difference? Should I still try doing the conversion to Int?
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  32. #32
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    no, if you have a text datatype in the DB, then you'll want to pass a string to it.

    Ok, lets try a different tack here for a minute and lets see if we can get the code working. Then we can muck around with parameters. We'll do it the no no way and see if it works.

    Comment out the lines dealing with parameters, remove the parameter from your SQL string, and replace the sql string line with this.

    Code:
    SelectCmd.CommandText = "SELECT reported_user, reported_support, outage_details FROM tOutagesServer WHERE Srv_Ticket = '" & SRV_Ticket.Text & "'"
    Now this is a bad way to do it because you open yourself to sql injection. But, lets start with getting the code to work and we'll work our way back up to doing it correctly.

  33. #33

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    Edit - Just scrolled over and I see you've concantenated the VB with the Text line - i didn't scroll over far enough. I'll do that now, but given I had removed ALL indications of a parameter and I'm still getting the error message, I feel that's significant (but how I have no clue). Now I know what House feels like.....

    Done. And I'm still getting stuck on the DA.Fill(DS) line, with the same error ("{"No value given for one or more required parameters."}").

    I've remm'd out the Select statement and replaced it with a straight "select reported_user, reported_support, outage_details from toutagesserver", and i've also remm'd out my DA.SelectCommand.Parameters.AddwithValue("@Srv_ticket","Srv_Ticket.txt") and the DA.SelectCommand.Parameters.Clear().

    OK, so I just tried your concantenated VB and still get the error. However, (and I really hope this has nothing to do with it), the Subroutine I've got just above this one has three parameters, @Srv_Ticket, @Srv_DateTimeNotified, and @Srv_SupportRequested. I've remm'd out the entire routine and still get the error, so I'm thinking not, but hey, what do I know LOL

    OK, *now* I'm going for lunch. Thank God I brought pasta, I'm going to need the carbs to survive this aft!!
    Last edited by chr1spy1; Oct 13th, 2009 at 10:47 AM.
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  34. #34
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    ok, hrm, this is getting frustrating. Lets try and do this the long winded way of adding a parameter

    Code:
    Dim SRV_Ticket As New OleDb.OleDbParameter("SRV_Ticket_Parameter", OleDb.OleDbType.Char) 
    
    SRV_Ticket.Value = SRV_Ticket.Text
    
    DA.Parameters.Add(SRV_Ticket)
    Had to do a little work because i never use access as a DB, so I figured there might be some minute differences between the two. You can read more about what i posted here

    http://social.msdn.microsoft.com/for...f-11cbf934e0b0

    Although he is asking about executing multiple queries, the logic behind getting it setup is what you need to know.

  35. #35

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    OK, this is getting stupid. Still no luck, still getting stuck at the same line.

    I'm thinking of clearing this entire subroutine and re-write it from scratch. I doubt that will make any difference but hey, you never know.

    I also tried removing the LostFocus method and putting it to a button, desperate to try anything. Still nothing.

    And people don't believe me when i say I spend 7 hours on one single line of code LOL
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  36. #36
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....


  37. #37

    Thread Starter
    Lively Member chr1spy1's Avatar
    Join Date
    Jan 2008
    Location
    Either I'm Tron or I'm stuck in SQL Server...
    Posts
    105

    Re: All I need to do is populate my form....

    *sigh*...i've put a single quote around everything I could think of, and I'm still getting stuck on this one single @%&*!!! line of code; everything else runs fine, either with or without the quotes. Argh. I'm off on vacation next week and I need to have this app finished by Thursday afternoon. Not going to happen if I continue to run into problems like this. I'm thinking I put this particular form on hold for now and come back to it later.
    Thanks BackwoodsCoder and Chris128, I really appreciate all your help. I'm going home shortly but will be logged back in shortly after dinner, so please - any far-fetched, potentially insane ideas are most welcome.
    Thanks again....
    Chris
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GIT d-@ s: a C++++ U--- P> L> E- W+++ N o k- w--- o-- M- V? PS++ PE- Y+ PGP- t+ 5> X+++ R> tv+ b+++ DI+++ D+ G++ e++ h--- r+++ y+++
    ------END GEEK CODE BLOCK------

  38. #38
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: All I need to do is populate my form....

    Are you ready to kick yourself? You forgot a ";" at the end of your connection string. You MUST put that after each section of your connection string. It should look like this:
    Code:
    Dim connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\....\Notifications.mdb;")
    I tested it and had no problems with it working. HOWEVER....if you get the same message, check (this means copy and paste) your column names between the database and the code in your app.

    *I hope that I am correct otherwise... *

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  39. #39
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: All I need to do is populate my form....

    Wait a minute....I think I may have found the problem....

    http://social.msdn.microsoft.com/For...f-8604d335c776

    Are you sure the column names you're querying are correct?

    and lastly (from that thread)

    Yes, that error message has nothing to do with the usage of a reserved words. The use of reserved words will generate a syntax error.

    When using OLEDB with ADO.NET named parameters are unsupported. Instead, remove the parameter names from your SQL statement and replace each with a question mark. In addition, you can remove the parameter names when adding parameters to the Parameter collection. Just make certain to add them to the collection in the order which corresponds to their order in the SQL statement.

    As I mentioned in my previous post, you may want to dump out the resulting SQL statement (strSQL) and post it here so we can take a look at it.

  40. #40
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: All I need to do is populate my form....

    When using OLEDB with ADO.NET named parameters are unsupported
    That is naff... why the hell does the OleDbCommand let you add named parameters if that is the case!
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Page 1 of 2 12 LastLast

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