[Solved] Why is this SqlCeCommand ExecuteReader call failing?

You forgot to open the connection. string connString = “Data Source=\”\\My Documents\\HHSDB003.sdf\””; string query = “SELECT * FROM MyTable”; SqlCeConnection conn = new SqlCeConnection(connString); SqlCeCommand cmd = new SqlCeCommand(query, conn); conn.Open(); // <— THIS SqlCeDataReader rdr = cmd.ExecuteReader(); try { // Iterate through the results while (rdr.Read()) { } } finally { // Always call … Read more

[Solved] Dividing one column into two columns in SQL [duplicate]

try this: DECLARE @YourTable table (Column1 varchar(50)) INSERT @YourTable VALUES (‘Frodo Baggins’) INSERT @YourTable VALUES (‘Samwise Gamgee’) INSERT @YourTable VALUES (‘Peregrin Took’) INSERT @YourTable VALUES (‘Meriadoc Brandybuck’) INSERT @YourTable VALUES (‘aa’) INSERT @YourTable VALUES (‘aa bb cc’) SELECT LEFT(Column1,CHARINDEX(‘ ‘,Column1)) AS Names ,RIGHT(Column1,LEN(Column1)-CHARINDEX(‘ ‘,Column1)) AS Surnames FROM @YourTable –both queries produce same output SELECT SUBSTRING(Column1, … Read more