Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 7th, 2003, 12:37 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid Sorting Example

I'm trying to run the example in Chapter 17 for DataGrid Sorting. I keep getting an error at the statement
objDataAdapter.Fill(objDataSet,"authors") the error is reported by the browser. I have used the same settings for the SQL Connection that were successful in the previous chapter, chapter 16(DataSet Example). Any help will be greatly appreciated.

 Thank you,

  #2 (permalink)  
Old July 7th, 2003, 01:38 PM
Authorized User
 
Join Date: Jun 2003
Location: Cowes, IOW, United Kingdom.
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JonathanC
Default

Hi SPRIBob

Off the cuff I would think that there may be a syntax error in your SQL. Wrap the code in a TRY CATCH and look at the Exception.ErrorMessage. Remember to look through the InnerExceptions as well to get further to the source of the error.

Here is the BindGrid() procedure as specified in the book. I have run this in both 2002 and 2003 and it works fine.

Grab the code below and replace your BindGrid with this one. If you have kept the name of the grid and so on as in the book, it will work first time, else you may have to modify the grid name etc.

Code:
 Sub BindGrid(ByVal strSortField As String)

        Dim objDataSet As DataSet
        Dim objDataAdapter As SqlDataAdapter

        objDataAdapter = New SqlDataAdapter("SELECT au_lname AS 'Last Name', au_fname AS 'First Name', " & _
            "title AS 'Book Title', price AS 'Retail Price' " & _
            "FROM authors " & _
            "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
            "JOIN titles ON titleauthor.title_id = titles.title_id " & _
            "ORDER BY au_lname, au_fname", objConnection)

        objDataSet = New DataSet
        objDataAdapter.Fill(objDataSet, "Authors")

        Dim objDataView As DataView = _
        objDataSet.Tables("Authors").DefaultView
        objDataView.Sort = strSortField
        grdAuthors.DataSource = objDataView
        grdAuthors.DataBind()

    End Sub


Let me know if it helps. :)

If not send me a mail and I will in turn reply with the entire project source as an attachment for you to look at.



Jonathan Crossland
http://www.jonathancrossland.com
  #3 (permalink)  
Old July 7th, 2003, 01:50 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan;

 I've just tried your code and I still get the same error. Server Error ...Login failed for user "computername\ASPNET".
I'm using the same connection string as I did in the SQL/ADO.NET example. I also have successfully run the Client-Server Processing example in this same chapter. Any help is greatly appreciated.

Thank you

  #4 (permalink)  
Old July 7th, 2003, 02:55 PM
Authorized User
 
Join Date: Jun 2003
Location: Cowes, IOW, United Kingdom.
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JonathanC
Default

Ok

This is a typical one :)

you probably have either the "integrated security=SSPI;" or
"Trusted_Connection = yes;" in your connectionstring
remove this and add "User ID=yourid;password=yourpassword"

read more
http://support.microsoft.com/default...b;en-us;316989



Jonathan Crossland
http://www.jonathancrossland.com
  #5 (permalink)  
Old July 8th, 2003, 08:41 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan;

  I've tried your latest suggestion and even implemented the example from the Microsoft Website. The following is the source code from the Page_Load procedure:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim con As New System.Data.SqlClient.SqlConnection("data source =localhost;" & _
         "trusted_connection=yes;uid=RUNIR315745300;pwd=;da tabase=pubs")
        con.Open()
        con.Close()
    End Sub

I get the same error ... Login failed for user 'RUNIR315745300\ASPNET'

If I remove the trusted_connection=yes the error becomes:
Login failed for user 'RUNIR315745300'. Reason: Not associated with a trusted SQL Server connection.
 This is getting very frustrating ... anymore insight to this problem?

Thanks again



  #6 (permalink)  
Old July 8th, 2003, 11:53 AM
Authorized User
 
Join Date: Jun 2003
Location: Cowes, IOW, United Kingdom.
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JonathanC
Default

Hi SPRIBob

I understand your frustration.

Please read through the following similar thread and try the suggestions put forward.

http://p2p.wrox.com/topic.asp?TOPIC_ID=524


Pay special attention the sql password and sql instance comments
example the comments made about the connectionstring - "data source=MACHINENAME\VSDOTNET"

Jonathan


Jonathan Crossland
http://www.jonathancrossland.com
  #7 (permalink)  
Old July 8th, 2003, 01:04 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan;

  I think I'm getting closer(I hope) ... here are the changes I've made to this test program:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim con As New System.Data.SqlClient.SqlConnection("data source=RUNIR315745300\VSDOTNET;" & _
         "Initial Catalog=pubs;Integrated Security=sspi;Workstation ID=RUNIR315745300")
        con.Open()
        con.Close()
    End Sub

When double clicking the tray icon for SQL Server I get the following:
Server: RUNIR315745300
Services: SQL Server

on the very bottom of this little form is:
"Running - \\RUNIR315745300 - MSSQLServer" ... when attempting to run this I get a new error:

"SQL Server does not exist or access denied."

I very much appreciate your help.

Thanks again

  #8 (permalink)  
Old July 16th, 2003, 08:19 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan;

  I'm progressing along, still in Chapter 17 and still with the DataGrid Updates example. When I attempt to edit a row and select update, I get the following server error ...
Server Error in '/DataGrid Updates' Application.
--------------------------------------------------------------------------------

Prepared statement '(@ID varchar(6),@Title varchar(80),@Price money)UPDATE titles SE' expects parameter @Price, which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Prepared statement '(@ID varchar(6),@Title varchar(80),@Price money)UPDATE titles SE' expects parameter @Price, which was not supplied.

I'm pasting in the UpdateGridData procedure from my project...

        Sub UpdateGridData(Sender As Object, E As DataGridCommandEventArgs)
         Dim objCommand As SqlCommand
         Dim objTextBox As TextBox

         Dim strSQL As String = "UPDATE titles " & _
             "SET title = @Title, price = @Price " & _
             "WHERE title_id = @ID"

         objCommand = New SqlCommand(strSQL, objConnection)
         objCommand.Parameters.Add(New SqlParameter("@ID", SqlDbType.VarChar, 6))
         objCommand.Parameters.Add(New SqlParameter("@Title", SqlDbType.VarChar, 80))
         objCommand.Parameters.Add(New SqlParameter("@Price", SqlDbType.Money, 8))

         objCommand.Parameters("@ID").Value = _
            grdAuthors.DataKeys(CInt(E.Item.ItemIndex))

         objTextBox = E.Item.FindControl("edit_title")
         objCommand.Parameters("@Title").Value = objTextBox.Text
         objTextBox = E.Item.FindControl("edit_price")

         If(Left(objTextBox.Text, 1) = "$")Then
          objTextBox.Text = Right(objTextBox.Text, Len(objTextBox.Text) -1)
         End If

         objCommand.Connection.Open()
         objCommand.ExecuteNonQuery()
         grdAuthors.EditItemIndex = -1
         objCommand.Connection.Close()
         BindGrid()
        End Sub

Any help will be greatly appreciated.

Thank you,


  #9 (permalink)  
Old July 21st, 2003, 11:58 AM
Authorized User
 
Join Date: Jun 2003
Location: Cowes, IOW, United Kingdom.
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JonathanC
Default


Hi

When you posted this, I was too busy to reply.
Are you still having this problem?

Jonathan Crossland
http://www.jonathancrossland.com
  #10 (permalink)  
Old July 25th, 2003, 07:01 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan;

   I actually went on from here and completed the book. I'm about to start the book Professional VB.NET. I would like to know what was wrong and what caused this error. It is the only unanswered problem I encounterred in the book.

Thank you,
SPRIBob

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid sorting Amorous ASP.NET 1.x and 2.0 Application Design 1 September 30th, 2005 11:44 PM
Sorting a datagrid trekmp ADO.NET 7 December 18th, 2004 06:56 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
DataGrid Sorting spm74 ASP.NET 1.0 and 1.1 Basics 3 May 26th, 2004 08:52 AM
Sorting a Datagrid - Help Please! Pauline VS.NET 2002/2003 0 August 29th, 2003 06:20 AM



All times are GMT -4. The time now is 02:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.