Bonjour

j'ai besoin d'aider si j'executer me donne un msg"ExecuteNonQuery : la propriété Connection n'a pas été initialisée."
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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.SqlClient;
using System.IO;
 
namespace courier
{
    public partial class Form1 : Form
    {   
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
         FileStream fsl = new FileStream(textBox1.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read);
         byte[]image = new byte[fsl.Length];
            fsl.Read(image,0, Convert.ToInt32(fsl.Length)); 
            fsl.Close();
         SqlConnection con = new SqlConnection(@"Data Source=NESTO-PC;Initial Catalog=courier;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("Insert Into document (typedoc,documen,reference,datearrive)Values('" + textBox2.Text + "','" + textBox1.Text + "', '" + textBox3.Text + "','" + textBox4.Text + "')");
           SqlParameter prm= new SqlParameter("textBox1.Text",SqlDbType.VarBinary,image.Length,ParameterDirection.Input,false,0,0,null,DataRowVersion.Current,image);
           cmd.Parameters.Add(prm);
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
}