نگفتی میخوای کجا ذخیره کنی؟ دیتابیس یا فایل؟
من کد ذخیره در فایل XML رو برات گذاشتم وقتی داده ها کمه یا برای ذخیره تنظیمات برنامه شدیدا توصیه میشه تو XML ذخیره بشه
[CSHARP]using System;
using System.Data;
using System.Windows.Forms;
namespace SAVEDATAINXMLFILE
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region SAVE DATA IN XML
DataTable table = CreateEmptyTable();
private void button1_Click(object sender, EventArgs e)
{
table.Rows.Add(1, "abc");
table.Rows.Add(2, "def");
table.Rows.Add(3, "DMD");
dataGridView1.DataSource = table;
}
static DataTable CreateEmptyTable()
{
DataTable table = new DataTable();
table.Columns.Add("Foo", typeof(int));
table.Columns.Add("Bar", typeof(string));
table.TableName = "MTable";
return table;
}
private void button2_Click(object sender, EventArgs e)
{
//Meego.XML is original
table.WriteXml("MeeGo.db", XmlWriteMode.IgnoreSchema);
}
private void button3_Click(object sender, EventArgs e)
{
table.ReadXml("MeeGo.db");
dataGridView1.DataSource = table;
}
private void button4_Click(object sender, EventArgs e)
{
table = CreateEmptyTable();
dataGridView1.DataSource = table;
}
private void Form1_Load(object sender, EventArgs e)
{
button4_Click(this,e);
}
}
#endregion
}
[/CSHARP]
اگر میخوای تو دیتابیس ذخیره کنی:
[url]http://www.softafzar.net/f5/%DA%A9%D8%A7%D8%B1-%D8%A8%D8%A7-%D8%AF%DB%8C%D8%AA%D8%A7%D8%A8%DB%8C%D8%B3-%D8%AF%D8%B1-%D8%B3%DB%8C-%D8%B4%D8%A7%D8%B1%D9%BE-768/[/url]