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

  • Home
  • SEARCH
  • 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 7942909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:07:01+00:00 2026-06-04T00:07:01+00:00

net to adding database. I am trying to do texts on two textbox and

  • 0

net to adding database. I am trying to do texts on two textbox and one selected value in dropdownlist to add my table.
Here is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string connectionString = @" Data Source=.\SQLEXPRESS;AttachDbFilename=C:\USERS\CEM\DOCUMENTS\VISUAL STUDIO 2010\WEBSITES\EKLEMEDENE\APP_DATA\DATABASE.MDF;Integrated Security=True;User Instance=True";
        string queryString = "INSERT INTO ekle(flight, name, food) VALUES   ('" + TextBox1.Text + " ' , '" + TextBox2.Text + " ' ,  '" + DropDownList1.SelectedValue + " '  )";
        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand command = new SqlCommand(queryString, con);
        con.Open();
        command.ExecuteNonQuery();

        con.Close();
    }
}

After I execute I will have error

Database ‘C:\Users\Cem\Documents\Visual Studio 2010\WebSites\eklemedene\App_Data\Database.mdf’ already exists. Choose a different database name.
An attempt to attach an auto-named database for file C:\USERS\CEM\DOCUMENTS\VISUAL STUDIO 2010\WEBSITES\EKLEMEDENE\APP_DATA\DATABASE.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

  • 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-04T00:07:03+00:00Added an answer on June 4, 2026 at 12:07 am
    1. You’re wide open for SQL-Injection. Avoid passing parameters directly from controls. Instead use Parameters.
    2. Use using-statement for anything implementing IDisposable like Connections or Commands:
    3. There’s something wrong with your ConnectionString, you could try to use SqlConnectionStringBuilder class:

    //Build the connection 
    SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder();
    
    //Put your server or server\instance name here.  Likely YourComputerName\SQLExpress
    bldr.DataSource = ".\\SQLEXPRESS";
    
    //Attach DB Filename
    bldr.AttachDBFilename = @"C:\USERS\CEM\DOCUMENTS\VISUAL STUDIO 2010\WEBSITES\EKLEMEDENE\APP_DATA\DATABASE.MDF";
    
    //User Instance
    bldr.UserInstance = true;
    
    //Whether or not a password is required.
    bldr.IntegratedSecurity = true;
    
    using(var connection = new SqlConnection(bldr.ConnectionString))
    {
        var sql = "INSERT INTO ekle(flight, name, food) VALUES (@flight, @name , @food)";
        using(var command = new SqlCommand(sql, connection))
        {
            command.Parameters.AddWithValue("@flight", TextBox1.Text);
            command.Parameters.AddWithValue("@name", TextBox2.Text);
            command.Parameters.AddWithValue("@food", DropDownList1.SelectedValue); 
            connection.Open();
            command.ExecuteNonQuery();
        }
    } // closes the connection implicitely
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a database to the App_Data location in an ASP.NET
I'm using .net framework 3.5 SP1. After adding a column to one table in
I'm having a problem adding a reference to a .NET assembly I built. Here's
i am building a database application in vb.net and i started by adding a
I'm building a simple multi-user (multi-tenant?) App with ASP.NET MVC3 and EF4, one database,
I'm trying to create a ASP.NET MVC 2 webapp using the Northwind database following
I've edited the webconfig in my Web Application (WebForms, .NET 4) adding this :
The .NET Framework is adding an ISet<T> interface with the 4.0 release. In the
I'm adding ASP.NET routing to an older webforms app. I'm using a custom HttpHandler
I have a problem adding ADO.Net Entity Data Model to my existing project, or

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.