How to generate List from SQL query?

I think this is what you’re looking for. List<String> columnData = new List<String>(); using(SqlConnection connection = new SqlConnection(“conn_string”)) { connection.Open(); string query = “SELECT Column1 FROM Table1”; using(SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { columnData.Add(reader.GetString(0)); } } } } Not tested, but this should work fine.

How to check if value is inserted successfully or not?

You can use @@ROWCOUNT server variable immediately after the insert query to check number of affected rows by the insert operation. declare @fName varchar(50) = ‘Abcd’, @lName varchar(50) = ‘Efgh’ INSERT INTO myTbl(fName,lName) values(@fName,@lName) PRINT @@ROWCOUNT –> 0- means no rows affected/nothing inserted –> 1- means your row has been inserted successfully For your requirement, … Read more

How to get month and year from Date field in sqlalchemy?

You can use following constructs to filter the Date column using either year or month: .filter(extract(‘year’, Foo.Date) == 2012) .filter(extract(‘month’, Foo.Date) == 12) And group_by is also possible: .group_by(sqlalchemy.func.year(Foo.Date), sqlalchemy.func.month(Foo.Date)) Now I haven’t tested it, but I assume that this might be slow because these queries result in full table scans, therefore I suggest you … Read more

SQLite loop statements?

Apparently the looping construct in SQLite is the WITH RECURSIVE clause. That documentation link has sample count-to-ten code, a Mandelbrot set plotter, and a Sudoku puzzle solver, all in pure SQL. Here’s an SQLite query that computes the Fibonacci sequence to give you a feel for it: sqlite> WITH RECURSIVE …> fibo (curr, next) …> … Read more

MySQL Workbench – How to clone a database on the same server with different name?

You can use migration wizard from MySQL Workbench. Just choose the same local connection in both source and target selection, then change schema name on manual editing step. If nothing appears on manual editing step click next and the source and targets will appear. Click slowly on the source database name and edit to the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)