Dear sirs,
we are facing new issue while inserting data via VB.net but same query if i execute via SQL server the data inserting
so please help to overcome this issue
VB code
Dim kSQL As String = Query6.Replace("@", Requestid)
Dim cmd1 As New SqlCommand(kSQL, sqlSoftcodeCn)
cmd1.CommandTimeout = 1000000
cmd1.ExecuteNonQuery()
cmd1.Dispose()
SQL: (query6 this will pass)
INSERT INTO PdcChequeRemovalMaillogs(Request_id,WORKFLOW_LINE_ID,ROLE_ID,LEVEL_ID,STATUS_ID) select Top 1 header_id,line_id,role_id,level_id,status_id from FnGetPdcChequeRemovalApproverWithLink(7) Order by Level_id
Abhishek YadavPosted Jul 25, 2024, 10:43 AM
Revised Code with Parameterized Query and Error Handling
Here is a revised version of your VB.NET code using parameterized queries and proper error handling:
Things to Check:
PdcChequeRemovalMaillogstable match those being inserted from theFnGetPdcChequeRemovalApproverWithLink(7)function.Further Debugging:
If the issue persists, add more detailed logging to understand what part of the process fails. You can also capture the exact SQL query generated and execute it directly in SQL Server Management Studio (SSMS) to verify it works outside the application.
By using parameterized queries and proper error handling, you can avoid common issues and improve the reliability and security of your database operations.
Nikunj SatasiyaPosted Jul 25, 2024, 10:40 AM
Yesubabu, can you try this soulution:
Amit MohantyPosted Jul 25, 2024, 10:35 AM
You cannot use @ as a parameter placeholder in your SQL query you need to properly defined and handled in the query string. SQL parameters need specific names in both the SQL query and when adding them to the SqlCommand object.
yesubabu kPosted Jul 25, 2024, 10:22 AM
No sir, same issue query is executing but data is not saving table level
Amit MohantyPosted Jul 25, 2024, 10:02 AM
Your Query6 does not contain the "@" symbol, so the replacement will have no effect.
Try this: