Registration page using Msaccess db

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 871
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Registration_in_Msaccess
{
public partial class Form2 : Form
{
//string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=beta 2.mdb;");
OleDbCommand com=new OleDbCommand();
string sql;

public Form2()
{
InitializeComponent();
}

private void btn_insert_Click(object sender, EventArgs e)
{
// OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
com.Connection = con;
sql = "INSERT INTO investinside([id],[emp],[unit],[dest],[detective],[state],[investdate],[investresult])VALUES(?,?,?,?,?,?,?,?)";

com.CommandText = sql;
com.Parameters.Clear();
com.Parameters.AddWithValue("id", idbox.Text);
com.Parameters.AddWithValue("emp", empbox.Text);
com.Parameters.AddWithValue("unit", unitbox.Text);
com.Parameters.AddWithValue("dest", destbox.Text);
com.Parameters.AddWithValue("detective", detectivebox.Text);
com.Parameters.AddWithValue("state", statebox.Text);
com.Parameters.AddWithValue("investdate", investdatebox.Text);
com.Parameters.AddWithValue("investresult", investresultbox.Text);
com.ExecuteNonQuery();
MessageBox.Show("Records inserted successfully");
con.Close();
}

private void Form2_Load(object sender, EventArgs e)
{
empbox.Items.Add("e001");
empbox.Items.Add("e002");

unitbox.Items.Add("1");
unitbox.Items.Add("2");

destbox.Items.Add("manager");
destbox.Items.Add("producer");

detectivebox.Items.Add("a");
detectivebox.Items.Add("b");

statebox.Items.Add("d");
statebox.Items.Add("e");

}
}
}

Comments or Responses

Login to post response