PDA

View Full Version : سوال: کار با بانک اکسس(نمایش در دیتا گرید ویو)



morrteza323
شنبه 25 دی 1389, 19:58 عصر
سلام دوستان عزیز من با این کد به بانکم (اکسس)اطلاعات وارد می کنم . خوب حالا می خوام با کد نویسی اطلاعات جدولم رو داخل دیتاگریدویو نمایش بدم.تو سایت سرچ کردم.اما هیچ کدوم از پست ها کمکم نکرد.لطفا منو راهنمایی کنید.


System.Data.OleDb.OleDbConnection ocn = new System.Data.OleDb.OleDbConnection();
System.Data.OleDb.OleDbCommand ocm = new System.Data.OleDb.OleDbCommand();
ocn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db1.accdb";
ocm.Connection = ocn;

ocm.CommandText = "INSERT INTO mbank (company_name,cala_p)VALUES(@a,@b)";
ocm.Parameters.Clear();
ocm.Parameters.AddWithValue("@a", textBox1.Text);
ocm.Parameters.AddWithValue("@b", textBox2.Text);
ocn.Open();
ocm.ExecuteNonQuery();
ocn.Close();
ocm.Dispose();

MortezaGity
شنبه 25 دی 1389, 20:38 عصر
دوست عزیز این کدشه. امیدوارم کمک کنه



/create the connection string
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\myDatabase.mdb";

//create the database query
string query = "SELECT * FROM MyTable";

//create an OleDbDataAdapter to execute the query
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);

//create a command builder
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);

//create a DataTable to hold the query results
DataTable dTable = new DataTable();

//fill the DataTable
dAdapter.Fill(dTable);

/the DataGridView
DataGridView dgView = new DataGridView();

//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();

//set the BindingSource DataSource
bSource.DataSource = dTable;

//set the DataGridView DataSource
dgView.DataSource = bSource;

mmd2009
یک شنبه 26 دی 1389, 01:03 صبح
با سلام

همینم کافیه :



string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\myDatabase.mdb";
string query = "SELECT * FROM MyTable";
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
DataTable dTable = new DataTable();
dAdapter.Fill(dTable);
dgView.DataSource = dTable