Accés au base des données avec C#
Bonjour tous le monde, je cherche de l'aide concernant un probleme d'accés a la base des données SQL server déja crée:
mon probleme c'est que je n'arrive pas à me connecter a la base des données avec C# sous VS 2008.
dans le fichier form1.cs il y a
Code:
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
| 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.Configuration;
using System.Data.SqlServerCe;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Data.Services;
namespace gestion_materiel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string id = textBox1.Text.Trim();
string lib = textBox2.Text.Trim();
string connectionString = "gestion_materiel.Properties.Settings.gest_materielConnectionString";
string requete = "INSERT INTO division VALUES(id,lib)";
SqlCeConnection connexion = new SqlCeConnection(connectionString);
connexion.Open();
SqlCeCommand sqlCommand = new SqlCeCommand(requete, connexion);
}
}
} |
et dans le fichier programs.cs
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace gestion_materiel
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
} |
et dans le fichier App.config
Code:
1 2 3 4 5 6 7 8 9 10
| <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="gestion_materiel.Properties.Settings.gest_materielConnectionString"
connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=gest_materiel;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration> |
si quelqu'un peut me dire oû est le probleme
merci d'avance.