Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 15th, 2009, 07:54 PM
Authorized User
 
Join Date: Dec 2009
Posts: 69
Thanks: 6
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
 
Old December 16th, 2009, 02: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
 
Old December 16th, 2009, 11:51 PM
Authorized User
 
Join Date: Dec 2009
Posts: 69
Thanks: 6
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
 
Old August 26th, 2010, 01:02 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old August 26th, 2010, 04:43 PM
Authorized User
 
Join Date: Dec 2009
Posts: 69
Thanks: 6
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Connection to Access Database reachsevar ASP.NET 2.0 Basics 1 November 28th, 2007 08:56 AM
Database connection Boris Kofman SQL Server 2005 9 January 18th, 2007 12:41 AM
database connection terry_s Beginning PHP 3 November 10th, 2004 05:05 AM
Database connection? RPG SEARCH ASP.NET 1.x and 2.0 Application Design 3 July 28th, 2004 08:42 AM





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