Csharp

Résolu
gerwech Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -  
 gerwech -
salut tout le monde,
j'ai une petite problème qui casse toujours ma tête, j'ai fait mon application avec visual studio 2010 et ma base de données avec My sql work bench...mon code est bien compiler sans aucune erreur mais lorsque j'exécute l'application une message d'erreur est affiché:
Message d'erreur: La référence d'objet n'est pas définie à une instance d'un objet
est que quelqu'un peut m'aider
voila c mon code source de la form d'insertion des données dans la base de données

Code source:


void Button3Click(object sender, System.EventArgs e)
{
if ((textBox11.Text.Length == 0) | (textBox12.Text.Length == 0) | (textBox13.Text.Length == 0) | (textBox14.Text.Length == 0) | (textBox15.Text.Length == 0)| (textBox16.Text.Length == 0) | (textBox17.Text.Length == 0) | (textBox18.Text.Length == 0) | (textBox19.Text.Length == 0) | (textBox20.Text.Length == 0))
{
MessageBox.Show("Veuillez remplir tous les champs",
"Erreur",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}

else
{


scnnCutting = new OdbcConnection(SQL_CONNECTION_STRING);
scnnCutting.ConnectionString = SQL_CONNECTION_STRING;
//scnnCutting.Open();
strSQL1 = string.Format("INSERT INTO service conversationnel (dureeMoyCommconver,TauxArrCommHconver,TauxActconver) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox2.Text + "' );");
strSQL2 = string.Format("INSERT INTO service interactif ( dureeMoyComminter,TauxArrCommHinter,TauxActinter) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox2.Text + "' );");
strSQL3 = string.Format("INSERT INTO service streaming (dureeMoyCStreaming,TauxArrCommStreaming,TauxActStreaming) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox2.Text + "' );");
strSQL4 = string.Format("INSERT INTO service (Gos) VALUES ('" + textBox1.Text + "');");
odbccmd = new OdbcCommand(strSQL4, scnnCutting);
odbccmd = scnnCutting.CreateCommand();
odbccmd.CommandText = strSQL1;
odbccmd.CommandText = strSQL2;
odbccmd.CommandText = strSQL3;
odbccmd.CommandText = strSQL4;
odbccmd.Connection = scnnCutting;

scnnCutting.Close();
//affichage
MessageBox.Show("Données de service conversationnel ajoutées avec succés");

MessageBox.Show("Données de service interactif ajoutées avec succés");

MessageBox.Show("Données de service streaming ajoutées avec succés");

MessageBox.Show("Données de service ajoutées avec succés");


}



this.Hide();
Divers d=new Divers();
d.Show();
}

ligne d'erreur:


strSQL1 = string.Format("INSERT INTO service conversationnel (dureeMoyCommconver,TauxArrCommHconver,TauxActconver) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox2.Text + "' );");

2 réponses

bart8686 Messages postés 81 Date d'inscription   Statut Membre Dernière intervention   84
 
Essaies en mode Debug ligne par ligne.
Généralement cette erreur vient du fait que ton objet est null... Essaies de déterminer lequel et pourquoi.
0
Utilisateur anonyme
 
il serai pas mal d'avoir aussi un visuel des déclaration de tes objet graphique et ceux de ton code

(par exemple je ne vois pas la déclaration de scnnCutting, strSQL1 , etc.)

naga
0
gerwech
 
merci bcp ...mais comment je peux faire debug ligne par ligne et comment je peux connaître est null ou non ? en principe elle doit être toujours Null !!
0
gerwech
 
salut , merci pour ton aide et voila c'est la déclaration des variables de cette interface d'ajout :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Odbc;


namespace Acceuil
{
partial class Ajouter
{

static String SQL_CONNECTION_STRING = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Acceuil;DSN=Acceuil;DESC=MySQL ODBC 5.1 Driver bdd;DATABASE=traffic;SERVER=localhost;UID=root;PORT=3306;OPTION=3;STMT=;";
Boolean DidPreviouslyConnect;
OdbcDataReader Reader0;
OdbcConnection scnnCutting;
string strSQL1;
string strSQL2;
string strSQL3;
string strSQL4;
OdbcCommand odbccmd;
0
Utilisateur anonyme
 
salut,
bon ca n'aide pas finalement ^^.
mais tu peux essayer :
dans la form qui contient tes zones de texte, il y a des éfichiers" rattaché, dont le "designer.cs". Dans ce fichier, change les attributs de tes textBox de private à public.
De même ta "partial class Ajouter", rajoute "public" devant ("public partial class Ajouter ")

mais je t'avoues que sans pouvoir tester, il me sera difficile de t'aider pour ce genre de problème =/.
naga
0