Question:
Help in Sql Program!?
Jadz
2010-11-25 22:44:21 UTC
Hi I've been getting syntax error in this program, Can anyone help me? I'm new to SQL.

Private Sub Form_Load()
'Declare the variable
Dim cnnNorthwind As ADODB.Connection
'Define a new Recordset
Dim rsEmployees As ADODB.Recordset
Dim strFName As String
Dim strLName As String
Dim datBirthDate As Date

'Open a connection using a DSN
Set cnnNorthwind = New ADODB.Connection
'Define the connection string as the DSN Northwind
cnnNorthwind.ConnectionString = "DSN= Northwind"
MsgBox "The Connection State is " & cnnNorthwind.State
cnnNorthwind.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Program Files\Microsoft Visual Studio\VB98\NWIND.mdb"
MsgBox "The Connection State is " & cnnNorthwind.State
'Execute the command on the connection, creating a Recordset
strName = InputBox("Please enter your First Name:")
strName = InputBox("Please enter your Last Name:")
strName = InputBox("Please enter your BirthDate:")
cnnNorthwind.Execute ("Insert into Employees (FirstName, LastName, Title, BirthDate) Values (' " & strFName & ' ", & strLName & ' ", 'Sales Representative', " & datBirthDate&")") <<<<<<<<<<<<<<<<<<<<<< This is my main Problem

Set rsEmployees = New ADODB.Recordset
Set rsEmployees = cnnNorthwind.Execute("Select FirstName, LastName FROM Employees WHERE Title = 'Sales Representative'", adCmdText)



'List all the names on the form
Do While rsEmployees.EOF <> True
lblNames.Caption = lblNames.Caption & vbCrLf & "" & _
rsEmployees.Fields("FirstName") & "" & _
rsEmployees.Fields("LastName")
rsEmployees.MoveNext
Loop
'Close the connection
cnnNorthwind.Close
MsgBox "The Connection State is " & cnnNorthwind.State



End Sub
Three answers:
Vishal
2010-11-25 23:01:21 UTC
("Insert into Employees (FirstName, LastName, Title, BirthDate) Values ('" & strFName & "', '"& strLName & "', 'Sales Representative','" & datBirthDate&"')")



it is a right....You have messed up the single qoute and double quotes
coffeend
2010-11-25 22:47:26 UTC
Values (' " & strFName & ' ", & strLName & ' ", 'Sales Representative', " &





not that familiar, but you might check your single and double quotes above. they look messed up.
anonymous
2016-10-18 04:58:49 UTC
a great style of bewilderment arises as a results of fact of ways those apps call their transaction programming languages. sq. (based question language) is an industry regular utilized by potential of all of the main relational DBMS (get admission to, Oracle, DB2, MySQL, sq. Server, and so on.) A given set of sq. code defines some action to the two regulate a database merchandise (CREATE table, DROP VIEW, and so on.) or retrieve/regulate information in the database (pick,INSERT,and so on.) apart from the occasional app-particular extension, the syntax of sq. does not variety from app to app...a pick is a pick in spite of whether this is in get admission to or Oracle. the various transaction languages are app-particular (PL/sq. for Oracle, T-sq. for sq. Server, and so on.). What they do is enable creation of procedural scripts that could contain sq. code surrounded by potential of high-quality judgment controlling the circumstances below which the sq. code is complete, besides as procedures for speaking with the consumer. The sq. code may be rather static with in straight forward terms particular parameters being inserted (many times assessment values in a the place clause) or dynamic the place the full sq. string is pieced jointly based upon the execution of the script. those procedural langages are in many situations comparable, however the top syntax will variety from app to app.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...