Praveen Maurya

Praveen Maurya

  • 1.8k
  • 146
  • 12.3k

How create A .exe file with SQL database and C# winform

Apr 27 2018 10:12 AM
HI there 
 
I am working on a simple inventory project. I have used Visual Studio 2010 with C# cod and SQL Server 2008 for my project. my project is going to be finished but at the mean time i want to run the project on my collage PC but the collage PC is neither having Visual Studio and nor SQL server so i have created a setup file using visual studio installer. all was looking good. i install that setup file on Collage PC but when i tried to fetch the database the problem Starts. the software is not getting the database.  here are my connection strings please check if i have to modify something.
this code is in my app.config file 
  1. <connectionStrings>  
  2.         <add name="const"  
  3.             connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Data.mdf;Integrated Security=True;User Instance=True"  
  4.             providerName="System.Data.SqlClient" />  
  5.     </connectionStrings>  
 and below code i have used in form
  1. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["const"].ConnectionString);  
 so the total form code is like this
 
  1. public partial class Form1 : Form  
  2.    {  
  3.        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["const"].ConnectionString);  
  4.        public Form1()  
  5.        {  
  6.              
  7.            InitializeComponent();  
  8.        }  
  9.   
  10.        private void Login_Click(object sender, EventArgs e)  
  11.        {  
  12.            SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From Login where Username='" + username.Text + "' and Password='" + password.Text + "'", con);  
  13.            DataTable dt = new DataTable();  
  14.            sda.Fill(dt);  
  15.            if (dt.Rows[0][0].ToString() == "1")  
  16.            {  
  17.                this.Hide();  
  18.                Main ss = new Main();  
  19.                ss.Show();  
  20.            }  
  21.            else  
  22.            {  
  23.                MessageBox.Show("please check Username and Password");  
  24.            }  
  25.        }  
  26.    }  
 
this is for login page cade..
 
please suggest need urgent help. 

Answers (4)