<pre lang="C#"><pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sell
{
public partial class category : Form
{
public category()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
log.Minimaze(this);
}
private void populate()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sell.Properties.Settings.DatabaseConnectionString"].ConnectionString))
{
con.Open();
string query = "select * from CategoryTbl ";
SqlDataAdapter sda = new SqlDataAdapter(query, con);
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
var ds = new DataSet();
sda.Fill(ds);
CatDGV.DataSource = ds.Tables[0];
con.Close();
}
}
private void label6_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void guna2DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
catid.Text = CatDGV.SelectedRows[0].Cells[0].Value.ToString();
catnom.Text = CatDGV.SelectedRows[0].Cells[1].Value.ToString();
catdis.Text = CatDGV.SelectedRows[0].Cells[2].Value.ToString();
}
private void guna2Button6_Click(object sender, EventArgs e)
{
if(catid.Text!="" && catnom.Text != "") {
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sell.Properties.Settings.DatabaseConnectionString"].ConnectionString)) {
try
{
con.Open();
string query = "insert into CategoryTbl values (" + catid.Text + ",'" + catnom.Text + "','" + catdis.Text + "')";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
MessageBox.Show("catégorie ajoutée avec succès");
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
}
populate();
catid.Text = "";
catnom.Text = "";
catdis.Text = "";
}else
{
MessageBox.Show("information manquante");
}
}
private void guna2Button5_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sell.Properties.Settings.DatabaseConnectionString"].ConnectionString))
{
try
{
if (catid.Text == "" || catnom.Text == "")
{
MessageBox.Show("information manquante");
}
else
{
con.Open();
string query = "update CategoryTbl set Nom ='" + catnom.Text + "',Description='" + catdis.Text + "'where Id =" + catid.Text + ";";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
MessageBox.Show("catégorie modifier avec succès");
con.Close();
populate();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
}
populate();
catid.Text = "";
catnom.Text = "";
catdis.Text = "";
}
private void guna2Button7_Click(object sender, EventArgs e)
{
using (SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["sell.Properties.Settings.DatabaseConnectionString"].ConnectionString))
{
try
{
if (catid.Text == "")
{
MessageBox.Show("Sélectionner la catégorie à supprimer");
}
else
{
Con.Open();
string query = "delete from CategoryTbl where Id =" + catid.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("catégorie suppremer avec succès");
Con.Close();
populate();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Con.Close();
}
}
populate();
catid.Text = "";
catnom.Text = "";
catdis.Text = "";
}
private void guna2Button3_Click(object sender, EventArgs e)
{
stock st = new stock();
st.Show();
this.Hide();
}
private void guna2Button9_Click(object sender, EventArgs e)
{
}
private void guna2Button8_Click(object sender, EventArgs e)
{
history history = new history();
history.Show();
this.Hide();
}
private void logout_Click(object sender, EventArgs e)
{
log log = new log();
log.Show();
this.Hide();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void guna2Button2_Click(object sender, EventArgs e)
{
sell sel = new sell();
sel.Show();
this.Hide();
}
private void guna2TextBox2_TextChanged(object sender, EventArgs e)
{
}
private void category_Load(object sender, EventArgs e)
{
populate();
}
private void guna2Panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
the problem is shown when I install the app on another computer, the laptop don't use the local database I made, and this is the app.config file
<pre>="1.0"="utf-8"
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="sell.Properties.Settings.DatabaseConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>