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.
Note:-
If you are facing problem to Add .mdf file in your solution Explorer then read following links:-
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 drop DataGridView 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.
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() |
13 | { |
14 | InitializeComponent(); |
15 | } |
16 |
17 | private void button1_Click( object sender, EventArgs e) |
18 | { |
19 | SqlConnection con = new SqlConnection(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( object sender, 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:
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.
Step 22 : If you want you can create setup file in visual studio 2012 and visual studio 2013 also.