Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:28:23+00:00 2026-05-31T21:28:23+00:00

I’m trying to learn about C# with SQL CE so that my program can

  • 0

I’m trying to learn about C# with SQL CE so that my program can remember stuff.

I have created a database and can connect to it:

SqlCeConnection conn = 
         new SqlCeConnection(@"Data Source=|DataDirectory|\dbJournal.sdf");
conn.Open();

And it connects right, I guess cause if I rename the dbJournal.sdf to something wrong it doesn’t debug right.

Let’s say I want to make a simple SELECT query.

(SELECT * FROM tblJournal)

How is that done?

What about a simple insert?

(INSERT TO tblJournal (column1, column2, column2) VALUES 
                                        (value1, value2, value3))

I’m used to PHP and MySQL (as you properly can see :o))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:28:25+00:00Added an answer on May 31, 2026 at 9:28 pm

    @Chuck mentions EntityFramework which simplifies things and does all the work of writing the sql for you.

    But there is a basic ADO.NET approach here which I will describe below.

    The classes follow a standard pattern so to insert/read from sql server or other databases there are exact replica classes like SqlConnection or OleDbConnection and OleDbCommand etc

    This is the most barebones ado.net approach:

    using( SqlCeConnection conn =
              new SqlCeConnection(@"Data Source=|DataDirectory|\dbJournal.sdf") )
    using( SqlCeCommand cmd = conn.CreateCommand() )
    {
      conn.Open();
      //commands represent a query or a stored procedure       
      cmd.CommandText = "SELECT * FROM tblJournal";
      using( SqlCeDataReader rd = cmd.ExecuteReader() )
      {
         //...read
      }
      conn.Close();
    }
    

    Then to read data :

    while (rd.Read())
    {//loop through the records one by one
         //0 gets the first columns data for this record
         //as an INT
         rd.GetInt32(0);
         //gets the second column as a string
         rd.GetString(1);
    }
    

    A nice and quicker way to read data is like this:

    using( SqlCeDataAdapter adap = 
              new SqlCeDataAdapter("SELECT * FROM tblJournal", "your connection") )
    {
      //the adapter will open and close the connection for you.
      DataTable dat = new DataTable();
      adap.Fill(dat);
    }
    

    This gets the entire data in one shot into a DataTable class.

    To insert data :

    SqlCeCommand cmdInsert = conn.CreateCommand();
    cmdInsert.CommandText = "INSERT TO tblJournal (column1, column2, column2) 
                               VALUES (value1, value2, value3)";
    cmdInsert.ExecuteNonQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.