SQLCommand insert error
SQLCommand insert error
SQLCommand insert error
SQLCommand insert error
SQLCommand insert error
SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error
SQLCommand insert error SQLCommand insert error
SQLCommand insert error
Go Back  Xtreme Visual Basic Talk > > > SQLCommand insert error


Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2005, 12:47 PM
19d20Scout 19d20Scout is offline
Newcomer
 
Join Date: Mar 2005
Posts: 5
Default SQLCommand insert error


Hey I'm working on a customer database and I'm having problems with my SQL insertion. This is my first time with VB.Net and MSDE

Code:
Private Sub btnCCAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCCAdd.Click Dim sqlConn As New SqlClient.SqlConnection Dim sqlCmd As SqlCommand Dim sqlText As String = "INSERT INTO CardType (cctypeName) Value('" & Trim(txtCCType.Text) & "')" sqlConn.ConnectionString = "Data Source=Jason\DB2000; Initial Catalog=dbDatabase; User Id=User; Password=Password;" Try sqlConn.Open() Catch sqlError As Exception MessageBox.Show(sqlError.Message, "Connection Error!") End Try sqlCmd = New SqlCommand(sqlText, sqlConn) sqlCmd.ExecuteNonQuery() sqlConn.Close() RefreshDisplay() End Sub


When I run this procedure I get the following error:
Quote:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.
Any ideas or help will be greatly appreciated.
Reply With Quote
  #2  
Old 03-18-2005, 02:09 PM
DTFan's Avatar
DTFan DTFan is offline
Junior Contributor
 
Join Date: Jul 2003
Location: Atlanta, Georgia
Posts: 230
Default

Quote:
Originally Posted by 19d20Scout
Code:
Private Sub btnCCAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCCAdd.Click Dim sqlConn As New SqlClient.SqlConnection Dim sqlCmd As SqlCommand Dim sqlText As String = "INSERT INTO CardType (cctypeName) Value('" & Trim(txtCCType.Text) & "')" sqlConn.ConnectionString = "Data Source=Jason\DB2000; Initial Catalog=dbDatabase; User Id=User; Password=Password;" Try sqlConn.Open() Catch sqlError As Exception MessageBox.Show(sqlError.Message, "Connection Error!") End Try sqlCmd = New SqlCommand(sqlText, sqlConn) sqlCmd.ExecuteNonQuery() sqlConn.Close() RefreshDisplay() End Sub
19d20Scout - Looks like the error is in the SQL statement itself. Add an 's' (without the single quotes) to the end of "Value" ... so your SQL statement should read ...

Code:
Dim sqlText As String = "INSERT INTO CardType (cctypeName) Values ('" & Trim(txtCCType.Text) & "')"

Hope that helps.
__________________

DTFan
Ever-hopeful programmer-in-training
:)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
SQLCommand insert error
SQLCommand insert error
SQLCommand insert error SQLCommand insert error
SQLCommand insert error
SQLCommand insert error
SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error SQLCommand insert error
SQLCommand insert error
SQLCommand insert error
 
SQLCommand insert error
SQLCommand insert error
 
-->