Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So in my project, I will let the user add the book that he wants, so I have created a new table for BooksAdded to users. so the user will choose the book and add it to the table, It will Insert the Book ID and the book name and the remaining quantity of the book from our main Books BookTbl and it will take the values for IssuedBy = loginscreen.username
and IssuedTIme = DateTime.now
How do I give these values any idea

I know that I am not using parameters i will use it later

sorry for the bad English

I wish you understand what I mean

What I have tried:

string mySQL = string.Empty;
           mySQL += "INSERT INTO IssuedBooksTbl (Book_ID, Book_Name, RemainingQuantity, IssuedBy, IssuedTime)";
           mySQL += "SELECT Book_ID, Book_Name, Quantitiy FROM BookTbl WHERE Book_ID='" + IDTxt.Text +"'";
           Connection.LibraryBooksServer.executeSQL(mySQL);


............................................
SO IssuedBy = loginscreen.username
and IssuedTIme = DateTime.now

how do i give the values for them any idea
Posted
Updated 14-May-21 3:55am
v2
Comments
SeanChupas 14-May-21 12:40pm    
Use a parameter query, not a concatenated one.

But I don't understand. You say that IssuedBy is coming from the username but then ask how you give those values.

No idea what you mean.
DerekT-P 15-May-21 17:00pm    
I think your question is how to structure the SQL given that your inserted values are primarily coming from another table..? When you use the "INSERT INTO [table] ([targetcolumns]) SELECT [sourcecolumns] FROM TABLE ..." form, there is a one-to-one mapping between the columns you're inserting, and the results of the SELECT statement. You're inserting 5 columns, so you need your SELECT to return 5 columns. You correctly have the first 3 of these from the source table, and you can then add your values as the next two columns. So the SELECT becomes something like SELECT Book_ID, Book_Name, Quantity, '" + loginscreen.username + "', GETDATE() Obviously do NOT concatentate your SQL like this, use a stored procedure with parameters. Here I'm using the Sql server current date/time via GETDATE but of course if you have a separate app server you can use the date/time from that by passing it in as a parameter, just like the username. Hope this helps. :-)
[no name] 16-May-21 16:55pm    
That's the answer ... I wasn't up for the explanation. :o)

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