سلام این کد نگاه کن ببین به دردت میخوره
من هم مشکل تورو داشتم و بالاخره به این نتیجه رسیدم :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
publicpartialclassForm1 : Form
{
OleDbConnection cnn;
OleDbDataAdapter da;
OleDbCommand cmd;
DataSet ds;
public Form1()
{
InitializeComponent();
}
privatevoid button1_Click(object sender, EventArgs e)
{
myAddData();
}
privatevoid myAddData()
{
cnn = newOleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb");
cnn.Open();
cmd = newOleDbCommand();
cmd.CommandText = "INSERT INTO tell (name, family, tell) VALUES ('mamali', 'programer', '021')";
cmd.Connection = cnn;
cmd.ExecuteNonQuery();
cnn.Close();
myShowAll();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
myShowAll();
}
privatevoid myShowAll()
{
cnn = newOleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb");
cnn.Open();
da = newOleDbDataAdapter("select * from tell", cnn);
ds = newDataSet("tell");
da.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].ToString();
cnn.Close();
}
}
}