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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:31:37+00:00 2026-06-01T03:31:37+00:00

I am creating a simple WPF Application with a Sql Connection. The problem is

  • 0

I am creating a simple WPF Application with a Sql Connection. The problem is that when i debug
the program it seems to be OK ( no errors ), but i cannot see my Data in the database.

private void button1_Click(object sender, RoutedEventArgs e)
    {
        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();

        conn.ConnectionString = @"DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MIKE.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

        try
        {
            SqlCommand SqlCmd = new System.Data.SqlClient.SqlCommand("INSERT INTO [Customer](FirstName,LastName) VALUES(@FirstName,@LastName)", conn);

            conn.Open();

            // Insert code to process data.
            SqlCmd.Parameters.AddWithValue("@FirstName", CUCFirstName.Text);
            SqlCmd.Parameters.AddWithValue("@LastName", CUClastName.Text);

            SqlCmd.ExecuteNonQuery();

        }
        catch (SqlException ex)
        {
            MessageBox.Show(ex.Message, ex.Number.ToString());
        }
        finally
        {
            conn.Close();
        }
    }

and my xaml code

 <Grid>
    <Button Content="Add" Height="66" HorizontalAlignment="Left" Margin="324,233,0,0" 
            Name="button1" VerticalAlignment="Top" 
            Width="135" Click="button1_Click" />

    <TextBox Height="36" HorizontalAlignment="Left" Margin="74,32,0,0" Name="CUCFirstName" 
             VerticalAlignment="Top" Width="242">
    </TextBox>

    <TextBox Height="39" HorizontalAlignment="Left" Margin="74,74,0,0" Name="CUClastName" 
             VerticalAlignment="Top" Width="242">
    </TextBox>

    <Label Content="First Name" Height="33" HorizontalAlignment="Left" Margin="324,32,0,0" 
           Name="label1" VerticalAlignment="Top" Width="151" />

    <Label Content="Last Name" Height="34" HorizontalAlignment="Left" Margin="324,72,0,0" 
           Name="label2" VerticalAlignment="Top" Width="151" />
</Grid>
  • 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-01T03:31:38+00:00Added an answer on June 1, 2026 at 3:31 am

    Every time you run the application a new instance of your database is copied to your debug folder (Because it is considered as resource).Put your database some where in local hard-drive like “C:\Test” and specify the same path in connection string.

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

Sidebar

Related Questions

I am creating a simple application with Django. I realized that I am doing
I'm creating a WPF (in c#) application that will create html files based on
I'm into creating a simple contact management application to test how WPF works with
I am creating a simple WPF Application. I've a function OpenFile: private void OpenFile(string
I'm using Console.WriteLine() from a very simple WPF test application, but when I execute
I'm creating a WPF MVVM application. I have a long process that I want
I'm creating a simple drawing application using WPF. I've run into some strange behaviour
In WPF, I am creating a simple custom control for my TODO program. It
i am creating simple call filter application which restrict unwanted calls. i use following
Was creating a simple console application to do some prototyping and was shocked to

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.