User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 402,682 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,290 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums

SQL AddWithValue problems

Join Date: Mar 2008
Location: Wales
Posts: 30
Reputation: BluePaper is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
BluePaper's Avatar
BluePaper BluePaper is offline Offline
Light Poster

Re: SQL AddWithValue problems

  #7  
Apr 30th, 2008
Ok so I've taken it, ripped it a part and glued it back together to fit my needs (see code below) now how can I go through the data/check that the row was found, is there a simple tutorial on datasets, adapters and such seeing as I'm used to coming from PHP & MySQL which is an entirely different ball game altogether.

Here's the code I've changed (will it still work? As I've said I don't know it too well and I'm learning on the go):

  1.  
  2. Dim sqlCmd As New SqlCommand()
  3. sqlCmd.CommandType = CommandType.Text
  4. sqlCmd.CommandText = "SELECT * FROM tUsers WHERE uAlias = @varAlias AND uPass = @varPass;"
  5. sqlCmd.Parameters.AddWithValue("@varAlias", txAlias.Text)
  6. sqlCmd.Parameters.AddWithValue("@varPass", varPassword)
  7.  
  8. Dim sqlCmdResults As New DataSet
  9. sqlCmdResults = sqlQuery(sqlCmd)

  1. Public Function sqlQuery(ByVal dbSqlCommand As SqlCommand) As DataSet
  2.  
  3. 'Set the connection string
  4. Dim dbConnectionString As String = "Data Source=LAMBDA\SQLEXPRESS;Initial Catalog=Rain;User ID=Skyrail;Password=*****"
  5. 'Create a database connection function
  6. Dim dbConnection As New SqlConnection(dbConnectionString)
  7. 'Set up the database adapter
  8. Dim dbAdapter As New SqlDataAdapter()
  9. 'Create a dataset to put data into
  10. Dim dbResultData As New DataSet()
  11.  
  12. 'Put the connection data into the function
  13. dbSqlCommand.Connection = dbConnection
  14. 'Something to do with the adapter
  15. dbAdapter.SelectCommand = dbSqlCommand
  16. 'Open the connection
  17. dbConnection.Open()
  18.  
  19. 'Try and put data into the adapter
  20. Try
  21. dbAdapter.Fill(dbResultData)
  22. Finally
  23. dbConnection.Close()
  24. End Try
  25.  
  26. Return dbResultData
  27. End Function

Thanks once again, it looks a lot cleaner now and I'm hoping it will work efficiently
Stone In Focus - Caffeine Group - CoffeePHP - Open Notes - Onyx - Redpoint Network - Espresso
Reply With Quote  
All times are GMT -4. The time now is 4:52 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC