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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:11:29+00:00 2026-06-15T00:11:29+00:00

i am beginner for windows mobile 6 and iam trying to pass values to

  • 0

i am beginner for windows mobile 6 and iam trying to pass values to database but itz not working there is no errors and warnings please check my code and help me.. database not updating..

private void button1_Click(object sender, EventArgs e)
{
  string conSTR = "data source= " +
    (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) +
    "\\DPass.sdf; Persist security info=False";


  SqlCeConnection connection = new SqlCeConnection(conSTR);
  SqlCeCommand cmd = new SqlCeCommand("INSERT INTO cusTable(Fname,Lname) VALUES(@Fname,@Lname)",connection);
  cmd.Parameters.AddWithValue("@Fname", textBox1.Text);
  cmd.Parameters.AddWithValue("@Lname", textBox2.Text);

  connection.Open();
  int affectedRows = cmd.ExecuteNonQuery();
  cmd.ExecuteNonQuery();
  MessageBox.Show("ela");
  connection.Close();
}
  • 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-15T00:11:31+00:00Added an answer on June 15, 2026 at 12:11 am

    Though not part of the solution, it’d be a good idea to move this outside of the loop so you don’t have to read this over and over.

    private readonly string CON_STR = "data source= " +
        (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) +
        "\\DPass.sdf; Persist security info=False";
    

    Now, use Try/Catch statements to find out what you’ve done wrong.

    In the modified code below, I’ve included 2 of these. The outer Try/Catch is set to Exception and will swallow any exception. The inner Try/Catch is the one I suspect will throw the message, and it is an SqlCeException, which is only thrown for SqlCe Errors.

    private void button1_Click(object sender, EventArgs e)
    {
       int affectedRows = 0;
       string sqlText = "INSERT INTO cusTable(Fname,Lname) VALUES(@Fname,@Lname)";
       try {
         using (var cmd = new SqlCeCommand(sqlText, new SqlCeConnection(CON_STR))) {
           cmd.Parameters.AddWithValue("@Fname", textBox1.Text);
           cmd.Parameters.AddWithValue("@Lname", textBox2.Text);
           try {
             cmd.Connection.Open();
             affectedRows = cmd.ExecuteNonQuery();
             //cmd.ExecuteNonQuery(); <= ?? Why are you calling this twice?
           } catch (SqlCeException ceEr) {
             MessageBox.Show(ceEr.Message, "SqlCe Error");
           } finally {
             cmd.Connection.Close();
           }
         }
       } catch (Exception err) {
         MessageBox.Show(err.Message, "Non-SqlCe Error");
       }
       MessageBox.Show(string.Format("Affected Rows: {0}", affectedRows), "ela");
    }
    

    It also appeared that you were calling your INSERT function twice, so the second ExecuteNonQuery() call has been commented out.

    Run this code, and report back with what the error message is and whether the title for that MessageBox is “SqlCe Error” or “Non-SqlCe Error”.

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

Sidebar

Related Questions

Iam beginner to windows services , i have a console application to transfer files
Beginner here trying to get a pipeline working in bash. If somebody can see
Where can I find tutorials and other beginner-level learning material for developing Windows Mobile
I'm an absolute beginner in Outlook programming and Windows GUI programming in general. But
I am beginner trying to develop a Windows service which keeps checking a folder
I am a complete beginner to working with windows services. I have a basic
I'm very beginner for developping. environment is .. Windows XP Professional SP3 Microsoft Visual
Beginner question: I have a dictionary where the values are lists of (a variable
I am a beginner with Windows Azure and I want to make an app
I am a absolute beginner in Windows Phone Development with a basic idea in

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.