Visual Studio中的数据库操作

Visual Studio中的数据库操作

问题描述:

大家好.

香港专业教育学院一直试图使用Visual Studio在sql Compact 3.5数据库中操作信息,但是我遇到了严重的问题.

如果谁是具有C#知识以及如何添加,删除和编辑信息的人,将非常感谢您的帮助.

语法和代码示例都将对我有所帮助
谢谢...

Good day to all.

Ive been trying to manipulate information in a sql compact 3.5 database using visual studio, but im having serious problems.

If the is anyone that has knowledge in C# and how to Add, Remove and Edit information your help would be much appreciated.

Both syntax and code examples will help me
Thanks...

只需使用标准的SQL命令:
Just use standard SQL commands:
DELETE FROM myTable WHERE Id=6
SELECT userName FROM myTable WHERE Id=6
UPDATE myTable SET userName='Joe' WHERE Id=6
INSERT INTO myTable (Id, userName) VALUES (7, 'Mike') (8, 'Jane')


C#代码与MsSql相同,只是您使用SqlCeConnection,SqlCeCommand等.


The C# code is just the same as for MsSql, only you use SqlCeConnection, SqlCeCommand, and so forth.

using (SqlCeConnection con = new SqlCeConnection(strConnect))
    {
    con.Open();
    using (SqlCeCommand com = new SqlCeCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }