473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Error in SQL INSERT INTO statement.

23
Table name:All_Table
I have a string value in string:strdata
A column in Table:login
How can i insert the string value in column"login"?
I tried this following code,but give syntax error msg.
Expand|Select|Wrap|Line Numbers
  1. strIns = "INSERT INTO All_Table
  2. (login) VALUES " & strdata "
Apr 10 '12 #1

✓ answered by NeoPa

In VBA that would be something like :
Expand|Select|Wrap|Line Numbers
  1. strVar = "INSERT INTO [All_Table] ([Login]) " & _
  2.          "VALUES ('" & strSomeString & "')"

7 2004
Rabbit
12,516 Expert Mod 8TB
The correct syntax for an insert statement is
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tableName (fieldName)
  2. VALUES ('field value')
Apr 10 '12 #2
usha2
23
Thank you.
When my field values are in string then what will be the syntax.
Apr 10 '12 #3
Rabbit
12,516 Expert Mod 8TB
That is the syntax for a string.
Apr 10 '12 #4
NeoPa
32,556 Expert Mod 16PB
In VBA that would be something like :
Expand|Select|Wrap|Line Numbers
  1. strVar = "INSERT INTO [All_Table] ([Login]) " & _
  2.          "VALUES ('" & strSomeString & "')"
Apr 11 '12 #5
Mihail
759 512MB
Declare a Public variable strData in a Public module (Of course you must remove the declaration from your actual module if it is not a public one)
In the same module design a function fGetData()

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Public strData As String
  3.  
  4. Public fGetData() As String
  5.     fGetData = strData
  6. End Function

Then use Rabbit's approach:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tableName (fieldName)
  2. VALUES (fGetData())
Apr 11 '12 #6
NeoPa
32,556 Expert Mod 16PB
I'm sorry to say Mihail, that while that approach may well work functionally, it is generally considered a clumsy one. Instead of tidying the design, it spreads out where the various elements can be found. Not an approach to recommend :-(

Furthermore, and possibly even more important a point, it is introducing a potentially considerable delay into the query. SQL queries are optimised to the data. If a VBA function is introduced into the mix in the WHERE clause then each record of input must be extracted (thereby bypassing most of the said optimisations) and processed through VBA code which is, at least partially, interpreted. Relatively speaking, this is like taking a bus to win a F1 Grand Prix. Far better to work out the correct SQL first in VBA, in a single process, then execute it at top speed.
Apr 11 '12 #7
Mihail
759 512MB
Good to know, NeoPa.
I provide a solution; I don't say that is the best one :)
Apr 11 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mvr | last post by:
Hi all I are using IIS 5.0, Oracle 8.1. I am having problem with the following Insert Statement when used on Production Web server with SSL(https://...., Verisign). This doesn't occur...
6
by: Kathy Burke | last post by:
Ugh. I'm using the following in an asp.net. I get an Syntax Error in INSERT INTO Statement on line Cmd1.ExecuteNonQuery(). I've made all my database fields text (just to eliminate that as a...
2
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
2
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
2
by: Paul Mason | last post by:
Hi folks, The ado.net stream appears to be not working so I'm here. The following function generates the error "Operation must use an updateable query". There is no identifiable or meaningful...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
7
by: Cindy H | last post by:
Hi I'm having a problem getting the insert statement correct for an Access table I'm using. The Access table uses an autonumber for the primary key. I have tried this: INSERT INTO Tournaments...
2
by: John | last post by:
The ASP application inserts transaction records in transaction table with the system time as the primary key. However, it is possible to have primary key violation because the records in...
6
by: BaWork | last post by:
I have the following to insert a new record: <% .. Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open "DSN=qqqqq;" SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount)...
3
by: DontB3 | last post by:
Hi, I'm new in this forum, and i hope someone can help. I'm creating an automatic application that transfer a database from Access -> DBF -> Oracle. When My App try to execute Insert SQL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.