This topic is locked
[SOLVED]

 SQL INSERT INTO SELECT

10/25/2018 2:41:42 PM
ASPRunner.NET General questions
K
kleanthis author

Can I have a SQL INSERT INTO SELECT in the After the record added event?

I try the following code but I get this error

[b][SqlException (0x80131904): Incorrect syntax near 'dbo.'.]runnerDotNet.Connection.query(XVar sql)[/b
My code is

//********** Insert a record into another table ************

string strSQLInsert = "insert into dbo.TestGrade (Class, UserIdStu, Divide) select class, UserId, Divide form dbo.StudentList where Class = '"+values["Class"].ToString()+"' and Divide ='"+values["Divide"].ToString()+"'";

CommonFunctions.db_exec(strSQLInsert, null);
K
kleanthis author 10/25/2018

Silly me!
The FROM must be in capital!!!!!
string strSQLInsert = "insert into dbo.TestGrade (Class, UserIdStu, Divide) select class, UserId, Divide FROMdbo.StudentList where Class = '"+values["Class"].ToString()+"' and Divide ='"+values["Divide"].ToString()+"'";

admin 10/26/2018



The FROM must be in capital!!!!!


Very wrong. Very wrong!
In original query you simply misspelled it. FORM vs FROM, the case doesn't matter.