Today,I am going to show how to create setup file(.exe) with SQL Database in visual studio 2010.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.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 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
Now continue with Next Button then you will see as shown below-->Next.
Step 6 : Now open Solution Explorer -->Add New Web Form --> drag and dropDataGridView control from toolbox-->and configure it as before.
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.
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace winsetup
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void
button1_Click(object sender, EventArgs e)
{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["newConnectionString"].ConnectionString);
con.Open();
String str = "insert
into student(Name,mobile,city) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
SqlCommand cmd = new
SqlCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
label4.Text = "Data has been
successfully inserted";
}
private void
button2_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
this.Hide();
frm2.Show();
}
}
}
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 -->clickpublish Button From left window as shown below:
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.
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.
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:
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.
No comments:
Post a Comment