1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace CsMac
{
/// <summary>
/// Logique d'interaction pour Window3.xaml
/// </summary>
public partial class Window3 : Window
{
private SqlDataAdapter dataAdapter;
private DataSet loginCredentials;
public Window3()
{
InitializeComponent();
}
private void Enr_Click(object sender, RoutedEventArgs e)
{
SqlConnection sqlcon = new SqlConnection("Data Source=TGOCLC0H5YV0\\SQLSERVER;Initial Catalog=CsMac; Trusted_Connection=True;");
try
{
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
string req = "INSERT INTO Demandes(CodeDmd, NomDemandeur, ServiceDemandeur, DesignationCs, Qte, PU, Total, DateEtHeure, Etat, Observation) VALUES (@CodeDmd, @NomDemandeur, @ServiceDemandeur, @DesignationCs, @Qte, @PU, @Total, @DateEtHeure, @Etat, @Observation)";
SqlCommand cmd = new SqlCommand(req, sqlcon);
dataAdapter = new SqlDataAdapter(cmd);
dataAdapter.Fill(loginCredentials);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new SqlParameter("@CodeCmd", txtcode.Text));
cmd.Parameters.Add(new SqlParameter("@NomDemandeur", txtnom.Text));
cmd.Parameters.Add(new SqlParameter("@ServiceDemandeur", txtservice.Text));
cmd.Parameters.Add(new SqlParameter("@DesignationCs", txtdesignation.Text));
cmd.Parameters.Add(new SqlParameter("@Qte", txtqte.Text));
cmd.Parameters.Add(new SqlParameter("@PU", txtpu.Text));
cmd.Parameters.Add(new SqlParameter("@Total", txttotal.Text));
cmd.Parameters.Add(new SqlParameter("@DateEtHeure", txtdate.Text));
cmd.Parameters.Add(new SqlParameter("@Etat", txtetat.Text));
cmd.Parameters.Add(new SqlParameter("@Observation", txtobservation.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Demande enregistrée.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlcon.Close();
}
}
}
} |
Partager