rowcount

PDO rowCount() works on MySQL but not in SQL Server 2008 R2

南笙酒味 提交于 2019-12-01 14:13:33
I have a problem when I get number of rows in SQL Server 2008 because my code works fine using MySQL but not in SQL Server. $sql = "SELECT TOP 1 U.Id , U.Name, U.Profile, P.Name NameProfile FROM sa_users U INNER JOIN sa_profiles P ON P.Id = U.Profile WHERE User = :user AND Pass = :pass"; $result = $this->dbConnect->prepare($sql) or die ($sql); $result->bindParam(':user',$this->data['username'],PDO::PARAM_STR); $result->bindParam(':pass',$this->data['password'],PDO::PARAM_STR); if (!$result->execute()) { return false; } $numrows = $result->rowCount(); $jsonLogin = array(); var_dump($numrows);

PDO rowCount() works on MySQL but not in SQL Server 2008 R2

南楼画角 提交于 2019-12-01 13:26:33
问题 I have a problem when I get number of rows in SQL Server 2008 because my code works fine using MySQL but not in SQL Server. $sql = "SELECT TOP 1 U.Id , U.Name, U.Profile, P.Name NameProfile FROM sa_users U INNER JOIN sa_profiles P ON P.Id = U.Profile WHERE User = :user AND Pass = :pass"; $result = $this->dbConnect->prepare($sql) or die ($sql); $result->bindParam(':user',$this->data['username'],PDO::PARAM_STR); $result->bindParam(':pass',$this->data['password'],PDO::PARAM_STR); if (!$result-

Error: number of bound variables does not match number of tokens

我们两清 提交于 2019-12-01 10:52:30
问题 I want to make an insert only if there's no correspondence in the db (mySQL) but he makes me not the statement. Here's the snippet if ($sql->rowCount() > 0) { echo 'Non inserisci'; } else { echo 'Inserisci'; $db->beginTransaction(); echo 'Ciao3'; $sql = $db->prepare("INSERT INTO contatti (nome,cognome) VALUES (?,?)") or die('Ciao2'); echo 'Ciao4'; $sql->execute(array($_POST['nome'],$_POST['cognome'])); echo 'Ciao5'; $db->rollBack(); } Where The SELECT is $db->beginTransaction(); $sql = $db-

Scope of @@rowcount?

梦想的初衷 提交于 2019-11-30 07:58:15
What is the scope of @@rowcount ? MSDN doesn't mention its scope. Returns the number of rows affected by the last statement. Ok. In my SP — I'm inserting into a table , which has a insert trigger which does another insertion when a new value is inserted to the table. Question: To which scope the @@rowcount will refer ? (trigger or SP) ? LittleBobbyTables Granted, the article is for SQL Server 2000, but one would hope the scope doesn't change between versions. According to the article How triggers affect ROWCOUNT and IDENTITY in SQL Server 2000 , @@ROWCOUNT will not be affected by triggers.

Datagridview rowcount showing 0 even when there is a valid datasource

帅比萌擦擦* 提交于 2019-11-29 16:08:14
I have a dynamically created DataGridView that has a valid DataSource with one row bound to it. However, it is returning me 0 when I am doing a rowcount on the DataGridView. dgResult.DataSource = resultDt; // a datatable containing one row flowLayoutPanel.Controls.Add(dgResult); int rows = dgResult.Rows.Count; // returning 0 always! Can someone please tell me where I may be going wrong here? I found the issue. I was displaying the grid in a tabbed page that was not selected. Unless the grid is visible, it does not raise the rowadded event (which is weird!) durnig databinding. I selected the

SQL Alchemy ResultProxy.rowcount should not be zero

╄→尐↘猪︶ㄣ 提交于 2019-11-29 13:24:20
Does anyone know how to get the row count from an SQL Alchemy query ResultProxy object without looping through the result set? The ResultProxy.rowcount attribute shows 0, I would expect it to have a value of 2. For updates it shows the number of rows affected which is what I would expect. from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker engine = create_engine( 'oracle+cx_oracle://user:pass@host:port/database' ) session = sessionmaker( bind = engine , autocommit = False , autoflush = False )() sql_text = u""" SELECT 1 AS Val FROM dual UNION ALL SELECT 2 AS Val FROM

Scope of @@rowcount?

旧街凉风 提交于 2019-11-29 10:48:45
问题 What is the scope of @@rowcount ?MSDN doesn't mention its scope. Returns the number of rows affected by the last statement. Ok. In my SP — I'm inserting into a table , which has a insert trigger which does another insertion when a new value is inserted to the table. Question: To which scope the @@rowcount will refer ? (trigger or SP) ? 回答1: Granted, the article is for SQL Server 2000, but one would hope the scope doesn't change between versions. According to the article How triggers affect

Return number of rows affected by SQL UPDATE statement in Java

混江龙づ霸主 提交于 2019-11-29 05:25:57
I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement("UPDATE user_table SET Level = 'Super' WHERE Username = ?"); prep1.setString(1, username); The update statement above works fine however I'd like to get the number of rows affected with this statement. Is this possible please? Calling executeUpdate() on your PreparedStatement should return an int, the number of updated records. Statement.executeUpdate() or execute() followed by getUpdateCount() will return the number of rows matched , not updated , according to the JDBC spec. If

SQL Server - does trigger affects @@Rowcount?

蓝咒 提交于 2019-11-29 03:22:32
I have a query which do UPSERT or update if exists and insert if not: update MyTable set [Name]=@NewValue where ID=@ID If @@RowCount = 0 insert into MyTable([Name]) values(@Name) Now, I wonder if the @@RowCount will be affected by a query executed in a trigger? Let us say in my trigger I have: insert into MyLogs(Description) values("Some description...") If the update is successful in my first query, the trigger will run the insert to MyLogs which will have affected rows. @@ROWCOUNT is tied to the scope of your current execution and is therefore unaffected by a trigger, which would run in a

Move SQL Server data in limited (1000 row) chunks

懵懂的女人 提交于 2019-11-28 21:32:41
I'm writing a process that archives rows from a SQL Server table based on a datetime column. I want to move all the rows with a date before X, but the problem is that there are millions of rows for each date, so doing a BEGIN TRANSACTION...INSERT...DELETE...COMMIT for each date takes too long, and locks up the database for other users. Is there a way that I can do it in smaller chunks? Maybe using ROWCOUNT or something like that? I'd originally considered something like this: SET ROWCOUNT 1000 DECLARE @RowsLeft DATETIME DECLARE @ArchiveDate DATETIME SET @ROWSLEFT = (SELECT TOP 1 dtcol FROM