Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 Display Modes
  #1 (permalink)  
Old December 15th, 2009, 06:54 PM
Authorized User
Points: 298, Level: 5
Points: 298, Level: 5 Points: 298, Level: 5 Points: 298, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 64
Thanks: 4
Thanked 0 Times in 0 Posts
Default Database connection

Hi Everyone,

I am desperate and need assistance, which I would appreciate very much.

I have the following code, which return the message:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll, and when I place the cursor on the highlighted green section I find this:

This code has called into another function. When that function is finished, this is the next statement that will be executed.

The code is:
<Private Sub ProjectFeed_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ProjectConnectionString As String = "Persist Security Info=False;Integrated Security=SSPI;database=Project;server=mySQLServer"
Dim ProjectConnection As New SqlConnection(ProjectconnectionString)
Dim ProjectCommand As SqlCommand = New SqlCommand
ProjectCommand.Connection = ProjectConnection
ProjectCommand.CommandText = "Insert into projects " & "(Project No,Client,Rate Type,Description,Starting date,Ending date, Location,Status,Comment,Manager)" & _
"values(@project No,@client,@Rate Type,@description,@starting date,@ending date, location,@status,@Comment,@Manager)"
ProjectCommand.Parameters.Add("Project No", txtProjectNo.Text)
ProjectCommand.Parameters.Add("Client", txtClient.Text)
ProjectCommand.Parameters.Add("Rate Type", cmbRate.Text)
ProjectCommand.Parameters.Add("Starting date", txtStart.Text)
ProjectCommand.Parameters.Add("Location", txtLocation.Text)
ProjectCommand.Parameters.Add("Status", cmbStatus.Text)
ProjectCommand.Parameters.Add("Comment", txtComments.Text)
ProjectCommand.Parameters.Add("Manager", txtManager.Text)
ProjectConnection.Open()
ProjectCommand.ExecuteNonQuery()
ProjectConnection.Close()

End Sub/>

Can someone please help.

Thanks
Khalil
  #2 (permalink)  
Old December 16th, 2009, 01:18 AM
Registered User
 
Join Date: Apr 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Column names with spaces require brackets

You have two column names with blanks. I believe these require square brackets around them to get valid SQL. That is Project No should be [Project No].

You also have parameter names with blanks, and I don't think those are allowed at all. See Microsoft's documentation for details:

http://msdn.microsoft.com/en-us/libr...2(SQL.80).aspx
  #3 (permalink)  
Old December 16th, 2009, 10:51 PM
Authorized User
Points: 298, Level: 5
Points: 298, Level: 5 Points: 298, Level: 5 Points: 298, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 64
Thanks: 4
Thanked 0 Times in 0 Posts
Thumbs down Database connection

Thank you very much for your help but am still unable to make it work.

I removed the spaces but still have the same issue. My understanding is whether I have spaces or not this is to do with executing the query, which is the stage that I haven't reached yet. My problem is to connect the database first.

I've tried a lot of things but no luck. It is a puzzle.

Thanks again
Khalil
  #4 (permalink)  
Old August 26th, 2010, 01:02 AM
Authorized User
 
Join Date: Dec 2006
Location: Tucson, AZ, USA.
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Default

It sound like some data format in table is defined differently may be text or number issue
I will use try and catch method to find the exact problem. If it doesnt work or you need more explaination on how to use try and catch method let me know
__________________
yvk
  #5 (permalink)  
Old August 26th, 2010, 04:43 PM
Authorized User
Points: 298, Level: 5
Points: 298, Level: 5 Points: 298, Level: 5 Points: 298, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 64
Thanks: 4
Thanked 0 Times in 0 Posts
Default Thank you

Hi Yasho,

You are right; it was a formatting problem and I've been able to resolve it.

Thank you very much

Regards
Khalil
 


Thread Tools
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
Database Connection to Access Database reachsevar ASP.NET 2.0 Basics 1 November 28th, 2007 07:56 AM
Database connection Boris Kofman SQL Server 2005 9 January 17th, 2007 11:41 PM
database connection terry_s Beginning PHP 3 November 10th, 2004 04:05 AM
Database connection? RPG SEARCH ASP.NET 1.x and 2.0 Application Design 3 July 28th, 2004 08:42 AM



All times are GMT -4. The time now is 08:48 PM.


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