Salut tt el monde
j'ai essayé de compiler le code suivant mais ça ne marche pas est ce que vous pouvez m'aider à trouver le probleme ? SVP , C urgent, Merci
PS : j'ai essayé le selectCommand et ça a marché alors le probleme en insertCommand Merci de m'aider
il ya aucun erreur mais lorsque je clique sur le boutun ça me donne le message de "erreur connexion"
using System;
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.Common;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void ValideInsc_Click(object sender, EventArgs e)
{
try
{
DbProviderFactory dbpf;
DbConnection oConn;
DbDataAdapter oDA;
dbpf = DbProviderFactories.GetFactory("System.data.sqlClient");
oConn = dbpf.CreateConnection();
oConn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Sohail_der\Mes documents\gestiondj.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
oDA = dbpf.CreateDataAdapter();
oDA.InsertCommand = oConn.CreateCommand();
oDA.InsertCommand.CommandText = "Insert into Client(Login, password, Nom, Prenom)values(@Login, @password, @Nom, @Prenom)";
DataSet oDS = new DataSet();
oDA.Fill(oDS, "Client");
oConn.Open();
string Log = loginInsc.Text;
string pass = PassInsc.Text;
string Nam = NomInsc.Text;
string Pren = PrenomInsc.Text;
DataRow dr = oDS.Tables["Client"].NewRow();
dr["Login"] = Log;
dr["password"] = pass;
dr["Nom"] = Nam;
dr["Prenom"] = Pren;
oDS.Tables["Client"].Rows.Add(dr);
DbParameter paraLogin = oDA.InsertCommand.CreateParameter();
paraLogin.SourceColumn = "Login";
paraLogin.ParameterName = "Login";
oDA.InsertCommand.Parameters.Add(paraLogin);
DbParameter parapassword = oDA.InsertCommand.CreateParameter();
parapassword.SourceColumn = "password";
parapassword.ParameterName = "password";
oDA.InsertCommand.Parameters.Add(parapassword);
DbParameter paraNom = oDA.InsertCommand.CreateParameter();
paraNom.SourceColumn = "Nom";
paraNom.ParameterName = "Nom";
oDA.InsertCommand.Parameters.Add(paraNom);
DbParameter paraPrenom = oDA.InsertCommand.CreateParameter();
paraPrenom.SourceColumn = "Prenom";
paraPrenom.ParameterName = "Prenom";
oDA.InsertCommand.Parameters.Add(paraPrenom);
int n = oDA.Update(oDS.Tables["Client"]);
MessageBox.Show("bien jouer");
oConn.Close();
}
catch
{
MessageBox.Show("Erreur de connexion!", "Valeur introuvable", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
Il te faut un SelectCommand avant de pouvoir faire le Fill()
insert en c# "urgent"
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.