ASP.NET and SQL - inserting data into more than one table? - asp.net

So I know similar questions have been asked before, but I couldn't find a clear answer for my specific situation. I'm using ASP.NET (in Visual Web Developer) and I need to insert data from one form into two separate tables. This is my data source:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/courseinfo.mdb"
SelectCommand="SELECT * FROM [tableCourse], [tableFaculty]"
InsertCommand="INSERT INTO [tableCourse]
([department], [name_first], [name_last], [prefix],
[course_number], [credits], [title], [description])
VALUES (?, ?, ?, ?, ?, ?, ?, ?); INSERT INTO [tableFaculty] ([name_first], [name_last], [phone], [email])
VALUES (?, ?, ?, ?)">
So you see I've tried using two insert statements, and it just comes back with an error saying there are extra characters after the SQL statement. I've tried taking out the semi-colon and then it says I'm missing a semi-colon. Is it possible to insert to two tables at once using this control? And if not, how do I work around this?
UPDATE:
Okay, tried it in the codebehind, but I don't think I did it right, now it's giving me this error:
Server Error in '/CCC' Application.
Index or primary key cannot contain a Null value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Index or primary key cannot contain a Null value.
Source Error:
Line 87:
Line 88: AccessDataSource1.InsertCommand = "INSERT INTO [tableCourse] ([department], [name_first], [name_last], [prefix], [course_number], [credits], [title], [description]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
Line 89: AccessDataSource1.Insert()
Line 90:
Line 91: AccessDataSource1.InsertCommand = "INSERT INTO [tableFaculty] ([name_first], [name_last], [phone], [email]) VALUES (?, ?, ?, ?)"
Line 89 is the one that's highlighted. So I'm thinking it's attempting to insert but for some reason the values are null, it isn't taking the values from the text boxes.
I probably left something obvious out, I don't know, I'm really new at this.

Why don't you give it a try at the codebehind?
AccessDataSource1.InsertCommand = "First INSERT Statement";
AccessDataSource1.Insert();
AccessDataSource1.InsertCommand = "Second INSERT Statement";
AccessDataSource1.Insert();

Related

Using WHERE NOT EXISTS in Sqlite returns syntax error

(This relates to a Discord bot using Discord.js and sqlite v3, NOT sqlite3)
I'm currently trying to use WHERE NOT EXISTS to add a row to my Sqlite table, but only if there isn't a row where "serverid" is the ID of the current server and the type spam already.
I tried it with this:
sql.run(`INSERT INTO filters WHERE NOT EXISTS(SELECT 1 FROM filters WHERE serverid = "${msg.guild.id}" AND type = "Spam") (serverid, type, active, action, time) VALUES (?, ?, ?, ?, ?)`, msg.guild.id, `Spam`, 0, `delete`, 60)
This works if there ISN'T a row with that ID and type yet, but as soon as it does exist, I get a "syntax error at: WHERE".
It doesn't tell me which WHERE the problem is, and I double checked the syntax multiple times and it should be fine.
Does this not work in sqlite? Or did I get the syntax wrong?
The syntax of the query is wrong.
You should use INSERT ... SELECT instead of INSERT ... VALUES:
INSERT INTO filters (serverid, type, active, action, time)
SELECT ?, ?, ?, ?, ?
WHERE NOT EXISTS(SELECT 1 FROM filters WHERE serverid = "${msg.guild.id}" AND type = "Spam")`

While making the bid in any one console i am getting this error in the cordapp-auction project

E 12:59:13+0530 [Node thread-1] spi.SqlExceptionHelper.logExceptions - Unique index or primary key violation: "PRIMARY_KEY_D ON PUBLIC.TRADE_STATES(OUTPUT_INDEX, TRANSACTION_ID) VALUES (0, '26EF53AD8C3CC7A99344B65B8469655FE9FE8ABB8DF98E1FEAC32425E122BFE4', 2)"; SQL statement:
insert into trade_states (amount, auctionReference, bidder, itemOwner, linear_id, output_index, transaction_id) values (?, ?, ?, ?, ?, ?, ?) [23505-194] {}
E 14:58:49+0530 [Node thread-1] spi.SqlExceptionHelper.logExceptions - Unique index or primary key violation: "PRIMARY_KEY_C ON PUBLIC.VAULT_STATES(OUTPUT_INDEX, TRANSACTION_ID) VALUES (0, '6FA36D1F62B0B20F9A4903AA175655E0D567116DB63D802DC7A6CB6E2C3EE3AE', 14)"; SQL statement:
insert into vault_states (consumed_timestamp, contract_state_class_name, lock_id, lock_timestamp, notary_name, recorded_timestamp, state_status, output_index, transaction_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-194] {}
E 14:58:49+0530 [Node thread-1] internal.ExceptionMapperStandardImpl.mapManagedFlushFailure - HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement] {}
ok when i am trying to make the bid from anyone console it is showing this error
2nd error
list is empty
when i am trying to close the auction
the project is from github (https://github.com/vardan10/cordapp-auction)
anyone can help me with this errors
Unfortunately, we will not be able to identify the issue with the above information. We would need more details for debug.
Furthermore, please refer to this official repository https://github.com/corda/samples for cordapp sample reference.

Symfony EasyAuditBundle error when insert into table

I got this error when it try to insert into the audit_lo table
An exception occurred while executing 'INSERT INTO audit_log (id,
type_id, type, description, event_time, user, impersonatingUser, ip)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)' with params [5,
"security.interactive_login", "security.interactive_login",
"security.interactive_login", "2017-11-22 12:56:48", "bmellor", null,
"::1"]:
and this log
Uncaught PHP Exception Doctrine\DBAL\Exception\SyntaxErrorException:
"An exception occurred while executing 'INSERT INTO audit_log (id,
type_id, type, description, event_time, user, impersonatingUser, ip)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)' with params [5,
"security.interactive_login", "security.interactive_login",
"security.interactive_login", "2017-11-22 12:56:48", "bmellor", null,
"::1"]: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error in or
close to «user» LINE 1: ..._log (id, type_id, type, description,
event_time, user, impe... ^" at
/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
line 70
I follow all the steps in here and inside config.yml
xiidea_easy_audit:
entity_class : AppBundle\Entity\AuditLog #Required
user_property : username #Optional
doctrine_entities : #Optional
AppBundle\Entity\SomeEntity : [created, updated, deleted]
events : #Optional
- security.interactive_login
EDIT
Environment
PHP 7.1.11
Symfony 3.3.X
PostgreSQL 9.6
EasyAuditBundle ^1.4
I've answer this question with 2 steps:
It seems like postgreSQL the column USER is reserved so I change it to user_data inside the entity
Changed impersonatingUser to nullable=true
And that works for me.

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 5 supplied [duplicate]

This question already has answers here:
Programming Error: Incorrect number of bindings supplied
(2 answers)
Closed 6 years ago.
I really do not understand what am I doing wrong. My table is:
conn.execute('''CREATE TABLE USERS
(EMAIL TEXT NOT NULL,
PASSWORD TEXT NOT NULL,
FIRST_NAME TEXT NOT NULL,
LAST_NAME TEXT NOT NULL,
DATE TEXT NOT NULL,
SEX TEXT NOT NULL);''')
and when I am trying to insert to the table:
conn.executemany("INSERT INTO USERS VALUES (?, ?, ?, ?, ?, ?)", [email, password, first_name, last_name, date, sex])
I get this error:
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 5 supplied.
if I add a question the error is the same but now:
sqlite3.OperationalError: table USERS has 6 columns but 7 values were supplied
if I add only a comma without a question mark the error is different:
sqlite3.OperationalError: near ")": syntax error
the variables value are:
email=str(myapp.register_email.text())
print email
first_name=str(myapp.first_name.text())
print first_name
last_name=str(myapp.last_name.text())
print last_name
date=str(myapp.date.text())
print date
password="nht"
print password
sex=str(myapp.sex.currentText())
print sex
I am really getting insane here cant figure out the problem
As suggested by the Python doc, the executemany() method requires a tuple of values. Therefore I suggest you to insert the new entry by using the following code:
conn.executemany("INSERT INTO USERS VALUES (?, ?, ?, ?, ?, ?)", [(email, password, first_name, last_name, date, sex)]

does Astyanax support cql 3 prepared statements?

I know that cassandra does but what about Astyanax? And does it escape single quotes in values? Thx
Yes it does,
You can see an example here https://github.com/Netflix/astyanax/wiki/Cql-and-cql3
final String INSERT_STATEMENT = "INSERT INTO employees (empID, deptID, first_name, last_name) VALUES (?, ?, ?, ?);";
result = keyspace
.prepareQuery(CQL3_CF)
.withCql(INSERT_STATEMENT)
.asPreparedStatement()
.withIntegerValue(222)
.withIntegerValue(333)
.withStringValue("Eric")
.withStringValue("Cartman")
.execute();

Resources