How to insert data/rows into MS Access Database

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hey guys!!

I am making a event manager to help organize the events in our company, and I can not figure out how to add new data to a database!!! Im super new to programming so please be super clear.... Thanks!

<pre class="prettyprint" style=" using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the database1DataSet.events table. You can move, or remove it, as needed.
this.eventsTableAdapter1.Fill(this.database1DataSet.events);


}


private void SaveData_Click(object sender, EventArgs e)
{

//dataGridView1.Rows.Add();


this.eventsTableAdapter.Fill(this.events.events);
OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersEvanDocumentsDatabase1.accdb;Persist Security Info=False;";
connect.Open();

OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "INSERT INTO Events VALUE (Some Event)";


command.Connection = connect;
command.CommandText = "SELECT EventName FROM events";

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())
{
listBox1.Items.Add(reader[0].ToString());
}


connect.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void tabPage3_Click(object sender, EventArgs e)
{

}

private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.eventsTableAdapter.FillBy(this.events.events);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}

}

private void button1_Click(object sender, EventArgs e)
{

}
}
}[/code]
<br/>

<br/>

View the full article
 
Back
Top