I have developed a windowsapplication in visual studio 2010 with back end of sql server database
Now i don't know how to creat setup of with my sql db.
I had tried to develop setup of windows application alone (with out back end DB).
If someone Knows Share it please .
Sushant ShindePosted Mar 3, 2016, 7:27 AM
Durga VelusamyPosted Sep 12, 2015, 3:27 AM
refer this below code
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int CustomerId = 0;
SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
con.Open();
SqlCommand com = new SqlCommand("select max(CustomerId) FROM devi", con);
if (com.ExecuteScalar().ToString() == "")
{
CustomerId = 0;
}
else
{
CustomerId = int.Parse(com.ExecuteScalar().ToString());
}
if (CustomerId > 0)
{
CustomerId = CustomerId + 1;
}
else
{
CustomerId = 1;
}
textBox1.Text = CustomerId.ToString();
MessageBox.Show("Id Created");
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
con.Open();
if ((textBox1.Text == "") && (comboBox1.Text == "") && (comboBox2.Text == "") && (comboBox3.Text == "") && (comboBox4.Text == ""))
{
MessageBox.Show("doesn't store null value");
}
else
if ((textBox1.Text == "") || (comboBox1.Text == "") || (comboBox2.Text == "") || (comboBox3.Text == "") || (comboBox4.Text == ""))
{
MessageBox.Show("Enter the nessary fields");
}
else
{
SqlCommand cmd = new SqlCommand("insert into devi Values('" + textBox1.Text + "','" + comboBox1.Text + "','" + comboBox2.Text + "','" + comboBox3.Text + "','" + comboBox4.Text + "','" + comboBox5.Text + "','" + comboBox6.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Added Successfully");
textBox1.Text = "";
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
comboBox4.Text = "";
comboBox5.Text = "";
comboBox6.Text = "";
}
}
private void button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
con.Open();
SqlCommand cmd3 = new SqlCommand("select* from devi where CustomerId='" + textBox1.Text + "' or PhoneNum='" + comboBox2.Text + "'", con);
SqlDataReader dr = cmd3.ExecuteReader();
if (dr.Read())
{
textBox1.Text = dr.GetValue(0).ToString();
comboBox1.Text = dr.GetValue(1).ToString();
comboBox2.Text = dr.GetValue(2).ToString();
comboBox3.Text = dr.GetValue(3).ToString();
comboBox4.Text = dr.GetValue(4).ToString();
comboBox5.Text = dr.GetValue(5).ToString();
comboBox6.Text = dr.GetValue(6).ToString();
}
else
{
MessageBox.Show("not found");
}
con.Close();
}
private void button4_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
con.Open();
SqlCommand cmd2 = new SqlCommand("update devi set CustomerId='" + textBox1.Text + "',PhoneNum='" + comboBox1.Text + "',CustomerName='" + comboBox2.Text + "',Address='" + comboBox3.Text + "' ,Area='" + comboBox4.Text + "',Mobile2='" + comboBox5.Text + "',LandLine='" + comboBox6.Text + "'where CustomerId='" + textBox1.Text + "'", con);
cmd2.ExecuteNonQuery();
MessageBox.Show("Edited");
textBox1.Text = "";
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
comboBox4.Text = "";
comboBox5.Text = "";
comboBox6.Text = "";
con.Close();
}
private void button5_Click(object sender, EventArgs e)
{
if ((textBox1.Text == "") && (comboBox1.Text == "") && (comboBox2.Text == "") && (comboBox3.Text == "") && (comboBox4.Text == "") && (comboBox5.Text == "") && (comboBox6.Text == ""))
{
MessageBox.Show("doesn't delete null value");
}
else
{
SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
con.Open();
SqlCommand cmd = new SqlCommand("Delete from devi where (CustomerId='" + textBox1.Text + "'or PhoneNum='" + comboBox2.Text + "')", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Deleted Successfully");
textBox1.Text = "";
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
comboBox4.Text = "";
comboBox5.Text = "";
comboBox6.Text = "";
con.Close();
}
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = "";
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
comboBox4.Text = "";
comboBox5.Text = "";
comboBox6.Text = "";
}
private void button7_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'basDataSet.devi' table. You can move, or remove it, as needed.
this.deviTableAdapter.Fill(this.basDataSet.devi);
}
}
}