parameterized-query

Escaping apostrophe/single quote in parameterized sql in asp

我们两清 提交于 2019-12-02 11:23:45
I'm new to parametrized SQL. I've got a query in an .asp page that's getting one or more client names from a form. These are held in an array called clientArr and then passed through to SQL server as parameters. I'm escaping the ' as '' but this doesn't appear to be working. If I run the query with a client name like McDonald's , it returns no results. clientArr(y) = Replace(clientArr(y),"'","''" ... if qsClient > "" Then dim booComma booComma = false if mySQLwhere > "" Then mySQLwhere = mySQLwhere& " AND " End if mySQLwhere = mySQLwhere & " (p.client IN ( " for y = 0 to Ubound(clientArr) if

What is the correct way to form a parameterized SQL statement in C#

戏子无情 提交于 2019-12-02 08:51:06
问题 Objective: Using C# and SQL2008 correctly setup a Parameterized SQL Insert statement Issue: The following statement is used in a for loop so the values must be cleared. Upon running this code it states there is a syntax error near 250. The code is as follows for (int i = 0; i < Rows.Count; i++) { cmd.Parameters.Clear(); struct Row = (struct)Rows[i]; sql = "@RowName varchar(250) = null " + "INSERT INTO " + "database.dbo.table" + "(database.dbo.tabe.RowName) " + "VALUES " + "(@RowName) "; cmd

Parameterized Queries

孤者浪人 提交于 2019-12-02 08:26:44
I am currently learning parametrized queries as there are advantages to using them. Could someone give some pointers by converting this block of code to a parametrized version? Thanks. if(isset($_GET['news_art_id']) && (!empty($_GET['news_art_id']))) { $news_art_id = htmlentities(strip_tags($_GET['news_art_id'])); $news_art_id = validate_intval($news_art_id); //echo $news_art_id; $_SESSION['news_art_id'] = $news_art_id; // Assign value to status. $onstatus = 1; settype($onstatus, 'integer'); $query = 'SELECT M.id, M.j_surname, M.j_points_count, M.j_level, A.j_user_id,A.id, A.jart_title, A.jart

What is the correct way to form a parameterized SQL statement in C#

若如初见. 提交于 2019-12-02 06:35:36
Objective: Using C# and SQL2008 correctly setup a Parameterized SQL Insert statement Issue: The following statement is used in a for loop so the values must be cleared. Upon running this code it states there is a syntax error near 250. The code is as follows for (int i = 0; i < Rows.Count; i++) { cmd.Parameters.Clear(); struct Row = (struct)Rows[i]; sql = "@RowName varchar(250) = null " + "INSERT INTO " + "database.dbo.table" + "(database.dbo.tabe.RowName) " + "VALUES " + "(@RowName) "; cmd.CommandText = sql; cmd.Parameters.AddWithValue("@RowValue ", Row.RowName); } Thank you in advance for

ASP Classic VBscript Parameterized SQL Query?

廉价感情. 提交于 2019-12-02 05:40:59
问题 First post but thank you for all the help I've gotten from this site so far. I'm trying to parameterize an SQL query: query_url = Request.QueryString("ID") Set rs = Server.CreateObject("ADODB.Recordset") Set cmd = server.createobject("ADODB.Command") cmd.ActiveConnection = Internet_String cmd.CommandType = adCmdText cmd.CommandText = "SELECT NAME FROM OWNER.TABLE WHERE ID = " + "?" + "" Set param = cmd.CreateParameter(, , ,200 , Replace(query_url, "'", "''")) cmd.Parameters.Append param Set

preg_replace() is replacing too much

早过忘川 提交于 2019-12-01 21:18:34
问题 I am working on a simple SQL debugger which will accept parameterized variables and try to replace them accordingly so that if a piece of SQL has an issue then I can copy+paste it directly into my RDBMS to work with the query and hopefully debug an issue quicker. So far I essentially have this, but it is replacing too much: <?php $sql = "select * from table_name where comment like :a and email = :b and status = :c"; $patterns = array(); $patterns[0] = '/:a/'; $patterns[1] = '/:b/'; $patterns

PDO Error: “ Invalid parameter number: parameter was not defined”

强颜欢笑 提交于 2019-12-01 17:47:40
I am trying to use a simple MySQL insert query with the parameters in array form. It keeps telling me the number of parameters are wrong. I have tried the following, all producing the same error: $stmt3 = $link->prepare('INSERT INTO messages VALUES(null, :room, :name, :message, :time, :color)'); $stmt3->execute(array(':room' => $Clean['room'],':name' => $Clean['name'],':message' => $Clean['message'],':time' => $time,':color:' => $Clean['color'])); and $stmt3 = $link->prepare('INSERT INTO messages VALUES(:null, :room, :name, :message, :time, :color)'); $stmt3->execute(array(':null' => null, '

Parameterized DB2 Query From .NET

回眸只為那壹抹淺笑 提交于 2019-12-01 17:28:25
I am attempting to run a parameterized query against a DB2 database from .NET using the Client Access ODBC Driver using the following code: var db2Cmd = new OdbcCommand("INSERT INTO presnlats (LAT) VALUES (@LAT)", db2Conn); db2Cmd.Parameters.AddWithValue("@LAT", insertValue); Console.Out.WriteLine(db2Cmd.ExecuteNonQuery()); When executed, an OdbcException is thrown: ERROR [42S22] [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0206 - Column @LAT not in specified tables. The internets seem to imply that parameterized queries are supported by the client access ODBC driver, but this error seems to

Parameterized DB2 Query From .NET

两盒软妹~` 提交于 2019-12-01 16:30:13
问题 I am attempting to run a parameterized query against a DB2 database from .NET using the Client Access ODBC Driver using the following code: var db2Cmd = new OdbcCommand("INSERT INTO presnlats (LAT) VALUES (@LAT)", db2Conn); db2Cmd.Parameters.AddWithValue("@LAT", insertValue); Console.Out.WriteLine(db2Cmd.ExecuteNonQuery()); When executed, an OdbcException is thrown: ERROR [42S22] [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0206 - Column @LAT not in specified tables. The internets seem to

Parameterized Oracle SQL query in Java?

纵饮孤独 提交于 2019-12-01 08:29:58
I've been trying to figure out why the following code is not generating any data in my ResultSet: String sql = "SELECT STUDENT FROM SCHOOL WHERE SCHOOL = ? "; PreparedStatement prepStmt = conn.prepareStatement(sql); prepStmt.setString(1, "Waterloo"); ResultSet rs = prepStmt.executeQuery(); On the other hand, the following runs properly: String sql = "SELECT STUDENT FROM SCHOOL WHERE SCHOOL = 'Waterloo' "; PreparedStatement prepStmt = conn.prepareStatement(sql); ResultSet rs = prepStmt.executeQuery(); The data type for SCHOOL is CHAR (9 Byte). Instead of setString, I also tried: String sql =