Você está na página 1de 10

11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.

NET Tutorials

How To Create Setup File(.Exe) With Database In


Visual Studio 2010
On 03:06:00 By RAMASHANKER VERMA

Today,I am going to show how to create setup file(.exe) with SQL Database in visual studio 2010.In our previous
tutorial I have created a setup file(.exe) without including Database in Setup File.This method is purely different
to the previous setup creation method ,But it is very easy .Remember one things ,when you install this setup to
your desktop ,first install .NET Framework 4.0 or 4.5 in your machine otherwise it will give error.
There are some steps to create setup file with SQL Database, which are given below:
Step 1 : First open your visual studio -->File -->New-->Project-->Select Windows Forms Application -->OK--
>and drag and drop Label,TextBox & Button control on the Form from toolbox as shown below:

Step 2 : Now open Solution Explorer -->Right Click on project-->Add-->New Items-->Service-based


Database-->Click Add.

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 1/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

Note:-
If you are facing problem to Add .mdf file in your solution Explorer then read following links:-

Add Sql Database(.mdf)

Sql Server 2008 Problem

Step 3 : Now Double click on Database.mdf file-->Add New Table as shown below:

Step 4 : Now Enter your table column name-->and press save button as shown below:

Step 5 : Now go left window of your visual studio-->click Data sources (if not available then click
Data Button on top-->Click show Data sources)-->Add New Data source --> Select Data Source -->Next--
>Select Dataset -->Next-->Choose connection string -->Next

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 2/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

Now continue with Next Button then you will see as shown below-->Next.

Step 6 : Now open Solution Explorer -->Add NewWeb Form --> drag and drop DataGridView control
from toolbox-->and configure it as before.

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 3/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

Step 7 : Now open Solution Explore-->Right Click on Project -->Add New Reference-->.NET --> add Two
Namespace as given below-->OK

System.Configuration
System.Configuration.install

Step 8 : Now Double Click on Submit and Show Table Data Button and write the following codes as given
below.

01 using System;
02 using System.ComponentModel;
03 using System.Data;
04 using System.Drawing;
05 using System.Windows.Forms;
06 using System.Data.SqlClient;
07 using System.Configuration;
08 namespace winsetup
09 {
10 public partial class Form1 : Form
11 {
12 public Form1()

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 4/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials
13 {
14 InitializeComponent();
15 }
16
17 private void button1_Click(objectsender,
EventArgs e)
18 {
19 SqlConnection con
= newSqlConnection(ConfigurationManager.ConnectionStrings["newConnectionString"].ConnectionString);
20 con.Open();
21 String str = "insert into
student(Name,mobile,city) values('" +
textBox1.Text + "','" + textBox2.Text + "','" +
textBox3.Text + "')";
22 SqlCommand cmd = new SqlCommand(str,
con);
23 cmd.ExecuteNonQuery();
24 con.Close();
25 label4.Text = "Data has been
successfully inserted";
26 }
27 private void button2_Click(objectsender,
EventArgs e)
28 {
29 Form2 frm2 = new Form2();
30 this.Hide();
31 frm2.Show();
32 }
33 }
34 }

Step 9 : Now open App.config file from Solution Explorer --> change name and add same code in your
connection code as shown below:

Note:- Now i am going to create setup file with SQL Database as shown below .

Step 10 : Now open Solution Explorer -->Right click on the project -->Properties -->click publish Button
From left window as shown below:

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 5/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

Step 11 : Now First Create New folder (mysetup) on your Desktop .

Step 12 : Now Click Publishing Folder Location --> Select Your Folder(mysetup) from Desktop as
shown below-->click Open.

Step 13 : Now click Prerequisites Button-->Select following options as shown below-->OK.

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 6/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

Step 14 : Now click Options -->Write the required field as shown below-->OK

Step 15 : Now click Publish Wizard.. from bottom --> click Next as shown below.

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 7/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

Step 16 : Now proceed with Next Button --> click Finish .

Step 17 : Now click Publish Now Button from Bottom --> Your setup will be created in your Desktop
folder (mysetup).
see it:

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 8/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

Step 18 : Now First install .NET Framework 4.0 or 4.5 in your system,If you are using visual studio 2010
or 2012.After that you can install this setup.It will take few minutes.

Step 19 : Now Double click on setup Icon on the Desktop .You will see.

Step 20 : Now Enter the required field and click Submit Button.You will see.

Step 21 : Now Click Show Table Data Button.You will see.

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 9/10
11/1/2017 How to create setup file(.exe) with Database in Visual studio 2010 | MY.NET Tutorials

http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html#.WfmFmWiCzIU 10/10

Você também pode gostar