mind controll

mind controll

  • NA
  • 131
  • 60.6k

c# with ms access database urgent

Mar 20 2013 7:40 PM
i want to save data from :
idbox (textbox) - empbox (combobox) - unitbox (combobox) - destbox (combobox) -
detectivebox (combobox) - statebox (combobox) - investdate (datepicker) -
investresult  (textbox)
into the table investinside same order
id - emp - unit - dest - detective - state - investdate - investresult
i tried this one but didn't work plz help


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace beta_2
{
  public partial class Dentry_main : Form
  {
  OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=beta 2.mdb;");
  OleDbDataAdapter da;
  DataSet ds = new DataSet();
  OleDbCommand com=new OleDbCommand();
  string sql;
 
  public Dentry_main()
  {
  InitializeComponent();
  }
  private void Dentry_main_Load(object sender, EventArgs e)
  {

  }
  private void button1_Click(object sender, EventArgs e)
  {
  conn.Open();
  com.Connection = conn;
  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("success");
  conn.Close();

  }
  }
}


Answers (5)