Click here to Skip to main content
15,311,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i want insert data in acces file whit the query
string query = "INSERT INTO [USER] (Use_Sgi, Use_FirstName, Use_LastName, Use_Email, Use_MobilePhone, Use_BusinessPhone, Com_ID, Loc_ID ) values (@sgi,@nom,@prenom,@email,@telephonefix,@telphonemobile,@company,@localiter); select @@identity()";
                        OleDbCommand cmd = new OleDbCommand(query, con);
                        cmd.Parameters.AddWithValue("@sgi", txtsgi.Text);
                        cmd.Parameters.AddWithValue("@nom", txtnom.Text);
                        cmd.Parameters.AddWithValue("@prenom", txtprenom);
                        cmd.Parameters.AddWithValue("@email", txtemail);
                        cmd.Parameters.AddWithValue("@telphonefix", txttelphonefix);
                        cmd.Parameters.AddWithValue("@telphonemobile", txttelephonemobile);
                        cmd.Parameters.AddWithValue("@company", cbocompany.Text);
                        cmd.Parameters.AddWithValue("@localiter", cbolocaliter.Text);

                        con.Open();
                        var NewIdentity = cmd.ExecuteScalar();
                        con.Close();



i have error characters found after end of sql statement access

What I have tried:

How can I fix this issue ! Thx in advance
Posted
Updated 5-Feb-19 17:17pm
Comments
MadMyche 1-Feb-19 10:07am
   
What errors?
[no name] 1-Feb-19 10:14am
   
a.) Not clear for me what you mean with this: "i have error characters found after end of sql statement access"

b.) select @@identity()
Not sure about this, but should it not be select @@identity?

Instead of combining the query, try separate it out like


C#
string query = "INSERT INTO [USER] (Use_Sgi, Use_FirstName, Use_LastName, Use_Email, Use_MobilePhone, Use_BusinessPhone, Com_ID, Loc_ID ) values (@sgi,@nom,@prenom,@email,@telephonefix,@telphonemobile,@company,@localiter);";
...
...

con.Open();
//Execute the Insert
cmd.ExecuteNonQuery();

//now get the identity using the same connection
cmd.CommandText = "SELECT @@IDENTITY";
var NewIdentity = (int)cmd.ExecuteScalar();
Console.WriteLine("AutoNumber: {0}", NewIdentity );

con.Close();

Source:
Getting AutoNumber from Access via "SELECT @@IDENTITY" needs to be done in same connection as the INSERT. – Tips and tricks from a Developer Support perspective.[^]
   
v2
Comments
Maciej Los 5-Feb-19 11:54am
   
5ed!
SELECT t1.col, t3.col FROM table1 join table2 ON table1.primarykey = table2.foreignkey
join table3 ON table2.primarykey = table3.foreignkey
   
Comments
Richard Deeming 6-Feb-19 12:42pm
   
Not even a vague attempt to answer the question!
SELECT t1.col, t3.col FROM table1 join table2 ON table1.primarykey = table2.foreignkey
join table3 ON table2.primarykey = table3.foreignkey
   
Comments
Richard Deeming 6-Feb-19 12:42pm
   
And why have you posted this non-answer twice?!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900