Insert method 
Author Message
 Insert method
 I am trying to insert data from a windows form in C++ to my MS SQL
database.
I have only found how to use the insert function when the values are
constants.
INSERT INTO mytable(id,password)VALUES('78','work').

When I use variable names I get the error, cannot use column names.  But
these variable are not column names they are values I created to hold the
data from the edit control box.

Your help is greatly appreciated.



Fri, 06 Jan 2006 17:59:42 GMT
 Insert method

Quote:
> When I use variable names I get the error, cannot use column names.

Maybe you can show the code, but remember to use single quotes around char /
date variables while resolving the statement you are sending to the
database...


Fri, 06 Jan 2006 18:08:30 GMT
 Insert method
you must be missing putting single quotes around the column values.
Ex:
create table test2(i int, val varchar(50))
following insert statement will give you an error like '.... Column names
are not permitted'

insert into test values(1,a)

The correct statement would be

insert into test2 values(1,'a')

--
-Vishal


Quote:
> I am trying to insert data from a windows form in C++ to my MS SQL
> database.
> I have only found how to use the insert function when the values are
> constants.
> INSERT INTO mytable(id,password)VALUES('78','work').

> When I use variable names I get the error, cannot use column names.  But
> these variable are not column names they are values I created to hold the
> data from the edit control box.

> Your help is greatly appreciated.



Fri, 06 Jan 2006 18:11:17 GMT
 Insert method
You need to create the string that you will be passing to
the back end.Something like this.



HTH
Srinivas Sampangi

Quote:
>-----Original Message-----
>you must be missing putting single quotes around the
column values.
>Ex:
>create table test2(i int, val varchar(50))
>following insert statement will give you an error

like '.... Column names
Quote:
>are not permitted'

>insert into test values(1,a)

>The correct statement would be

>insert into test2 values(1,'a')

>--
>-Vishal



>> I am trying to insert data from a windows form in C++
to my MS SQL
>> database.
>> I have only found how to use the insert function when
the values are
>> constants.
>> INSERT INTO mytable(id,password)VALUES('78','work').

>> When I use variable names I get the error, cannot use
column names.  But
>> these variable are not column names they are values I
created to hold the
>> data from the edit control box.

>> Your help is greatly appreciated.

>.



Fri, 06 Jan 2006 18:20:58 GMT
 Insert method
You need to concatinate and pass the resultant string to
the backend .




variables.

HTH
Srinivas Sampangi

Quote:
>-----Original Message-----
> I am trying to insert data from a windows form in C++ to
my MS SQL
>database.
>I have only found how to use the insert function when the
values are
>constants.
>INSERT INTO mytable(id,password)VALUES('78','work').

>When I use variable names I get the error, cannot use
column names.  But
>these variable are not column names they are values I
created to hold the
>data from the edit control box.

>Your help is greatly appreciated.

>.



Fri, 06 Jan 2006 18:31:04 GMT
 Insert method
This is some of the code that is giving me a problem.

void Enrollment::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

DDX_Text(pDX,IDC_EDIT1,m_newmember);

DDX_Text(pDX, IDC_EDIT2,m_newpassword);

Quote:
}

// Enrollment message handlers

void Enrollment::OnBnClickedOk()

{

// When the user selects okay, the data will be stored in the database

UpdateData(TRUE);

m_newname="Jean Paul";

try

{

CDatabase dataSpeech;

CString strCmd="INSERT INTO sampleSpeech VALUES('''+ m_newmember +''','''
+m_newname +''','''+m_newpassword+''')";

if(dataSpeech.Open("SpeechVerify"))

{

dataSpeech.ExecuteSQL(strCmd);

dataSpeech.Close();

Quote:
}
}



Fri, 06 Jan 2006 18:37:25 GMT
 Insert method

Quote:
> dataSpeech.ExecuteSQL(strCmd);

Instead of this, how about printing strCmd to console or stdout and showing
us how it resolves.


Fri, 06 Jan 2006 18:45:00 GMT
 Insert method

Try this..

strCmd = "INSERT INTO sampleSpeech VALUES('" + m_newmember
+ "','" + m_newname + "','" + m_newpassword + "') "

HTH
Srinivas Sampangi

Quote:
>-----Original Message-----
>This is some of the code that is giving me a problem.

>void Enrollment::DoDataExchange(CDataExchange* pDX)

>{

>CDialog::DoDataExchange(pDX);

>DDX_Text(pDX,IDC_EDIT1,m_newmember);

>DDX_Text(pDX, IDC_EDIT2,m_newpassword);

>}

>// Enrollment message handlers

>void Enrollment::OnBnClickedOk()

>{

>// When the user selects okay, the data will be stored in
the database

>UpdateData(TRUE);

>m_newname="Jean Paul";

>try

>{

>CDatabase dataSpeech;

>CString strCmd="INSERT INTO sampleSpeech VALUES('''+

m_newmember +''','''

- Show quoted text -

Quote:
>+m_newname +''','''+m_newpassword+''')";

>if(dataSpeech.Open("SpeechVerify"))

>{

>dataSpeech.ExecuteSQL(strCmd);

>dataSpeech.Close();

>}

>}

>.



Fri, 06 Jan 2006 19:02:20 GMT
 Insert method
Thanks for your help.  It works now.


Fri, 06 Jan 2006 20:10:39 GMT
 
 [ 9 post ] 

 Relevant Pages 

1. inserting numeric value, API insert method question

2. fastest insert method for SQL server

3. Fastest insert method

4. Need to determine Insert Method

5. 1 * yFGXHfMNS-[MFC ODBC] Batch Insert Method

6. Batch Insert Method

7. 1 * zvPXaOjzl-[MFC ODBC] Batch Insert Method

8. Problem with Insert Method, Please Help...

9. How to intercept a call to the INSERT method ???

10. Inserting Blobs (Best Method)

11. Most Efficient method for Inserts

12. set method against update/insert/delete SQL Commands


 
Powered by phpBB® Forum Software