I am new to C #.
I created a local database in VS2010 (.sdf file). I am trying to create some comparisons between database columns. I successfully connected to the database using the following connection string:
string connectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;data source=c:\\users\\user\\documents\\visual studio 2010\\Projects\\myapp\\myapp\\mydb.sdf";
There are two tables in my database. Nicknames and names. Nicknames have one field called "Nickname", which simply lists the nicknames. Names have one field called "Text", which simply lists the names stored.
Example:
Nickname
Masher Jones Jaime John Joker
Names
John Adam Matt Jones
Let's say these are the values ββin my database. I want to find aliases that are not in the name table, which in my example are β Masher, Jaime and Joker.
How can i do this? I am using C # and VS2010.
Here is what I tried in terms of SQL codes:
"SELECT Alias FROM nicknames WHERE (NOT (Alias IN(SELECT Text FROM Names))) "; "SELECT Alias FROM nicknames EXCEPT SELECT Text FROM Names"; "SELECT Alias FROM nicknames t LEFT JOIN Names m ON m.Text = t.Alias WHERE m.Text IS NULL"; "SELECT Alias FROM nicknames UNION SELECT Text FROM Names";
What should I do?
EDIT
OleDbConnection conn = new OleDbConnection(connectionString); conn.Open(); string sql = "MYQUERYFROMTHEABOVEEXAMPLE"; OleDbCommand cmd = new OleDbCommand(sql, conn); OleDbDataReader reader; reader = cmd.ExecuteReader(); string result = ""; while (reader.Read()) { result += reader.GetString(0) + "\n"; }
This is what I use to read the results.
source share