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 8695477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:02:44+00:00 2026-06-13T01:02:44+00:00

Im testing out some database compact code using a simple form to add data

  • 0

Im testing out some database compact code using a simple form to add data to a database.
When I click the AddBtn, all I want is to insert some values from text fields into my database but instead I get this error “Format of the initialization string does not conform to specification starting at index 0.” And the problem seems to be within the SqlCeConnection row.

Complete code sample:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Data.SqlServerCe;

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
        InitializeComponent();
            }

            private void AddBtn_Click(object sender, EventArgs e)
            {
                SqlCeConnection con = new SqlCeConnection(@"C:\Users\Name\Documents\Visual Studio         2012\Projects\DataBaseTest\MyDatabase#1.sdf");
                try {
                    con.Open();

                    SqlCeCommand cmd = con.CreateCommand();

                    cmd.CommandText = "insert into test ([ID], [OrderID], [KundID]) values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"')";

                    try {
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex) {
                        MessageBox.Show(ex.Message);
                    }


                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }
  • 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-06-13T01:02:46+00:00Added an answer on June 13, 2026 at 1:02 am

    You are not using a valid connection string (add 'Data Source=' before the path to the SDF.
    See the MSDN documentation for SqlCeConnection.

    SqlCeConnection con = new SqlCeConnection(@"Data Source=C:\Users\Name\Documents\Visual Studio         2012\Projects\DataBaseTest\MyDatabase#1.sdf"
    

    Other than that do not use the text of the buttons directly in the query (leaves you open to SQL injection attack) use SQL parameters instead (again MSDN is your friend.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pull some data out of our testing database with an
i'm just testing out the csv component in python, and i am having some
I have just started out with testing some php mvc framework In it, it
Testing out someone elses code, I noticed a few JSP pages printing funky non-ASCII
I am having issues testing out the Scala Parser Combinator functionality for a simple
I am writing some testing software that receives some source code, compiles it on
I am learning cakePHP 1.26. I got some sample data in a Table Testing
Every change of data in some row in database should save the previous row
I've got this issue with database locking when I'm testing some threading features I've
I'm testing out some SQL CLR stuff in VS 2008 and SQL Server 2005,

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.