این کد ستونهای دیتا گرید
private void Register_Click(object sender, EventArgs e)
{
my_con.ConnectionString = cs;
OleDbCommand my_com = new OleDbCommand();
my_com.Connection = my_con;
my_com.CommandType = CommandType.Text;
my_com.CommandText = "insert into table1(text1,text2,text3,text4) values(@text1,@text2,@text3,@text4)";
my_com.Parameters.AddWithValue("@text1", text1.Text.Trim());
my_com.Parameters.AddWithValue("@text2", text2.Text.Trim());
my_com.Parameters.AddWithValue("@text3", text3.Text.Trim());
my_com.Parameters.AddWithValue("@yext4", text4.Text.Trim());
DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "text1";
col.Width = 30;
col.HeaderText = "text2";
col.Width = 1200;
col.HeaderText = "text3";
col.Width = 50;
col.HeaderText = "text4";
col.Width = 80;
my_con.ConnectionString = cs;
if (my_com.Connection.State != ConnectionState.Open)
{
my_com.Connection.Open();
}
my_com.ExecuteNonQuery();
text1.Clear();
text2.Clear();
text3.Clear();
text4.Clear();
my_con.Close();
Form1_Load(sender, e);
text1.Focus();
}
این هم لینک دیتا اکسس است
public Form1()
{
InitializeComponent();
}
OleDbConnection my_con = new OleDbConnection();
string cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\DF.accdb";
OleDbDataAdapter Da = new OleDbDataAdapter();
private void Form1_Load(object sender, EventArgs e)
{
my_con.ConnectionString = cs;
Da.SelectCommand = new OleDbCommand();
Da.SelectCommand.Connection = my_con;
Da.SelectCommand.CommandType = CommandType.Text;
Da.SelectCommand.CommandText = "Select * from table1";
if (Da.SelectCommand.Connection.State != ConnectionState.Open)
{
Da.SelectCommand.Connection.Open();
}
DataTable dt = new DataTable();
Da.Fill(dt);
dataGridView1.DataSource = dt;
my_con.Close();
}
همش درسته فقط اینکه چون کولیکشون ندارم فرم دیتا گرید ویو هربار بهم میخورد