0
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.IO;
using System.Data.OleDb;
using System.Data.Common;


namespace subok
{
public partial class Form1 : Form
{
public OleDbConnection connect;
static string strconnect = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Documents and Settings\avupdate\My Documents\db3.mdb";
public OleDbDataAdapter adapter;
public DataSet dtset;
public OleDbCommand cmd;
public Form1()
{
InitializeComponent();
}


private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'db3DataSet.record' table. You can move, or remove it, as needed.

this.recordTableAdapter.Fill(this.db3DataSet.record);
connect = new OleDbConnection(strconnect);
connect.Open();
MessageBox.Show("Bukas na ang database!", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form1 subok =new Form1();
subok.Show();

}

private void button1_Click(object sender, EventArgs e)
{
//view
dtset = new DataSet("test");
cmd = new OleDbCommand("select*from record");
cmd.CommandType = CommandType.Text;
cmd.Connection = connect;
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dtset);
dtset.Tables[0].TableName = "test";
dataGridView1.DataSource = dtset.Tables["test"];
}



private void button3_Click(object sender, EventArgs e)
{
//add
cmd = new OleDbCommand("Insert into record(snum, lastname, fmane, MI, age, bday)" + "values(" + "'" + textBox1.Text + "'" + ", " + "'" + textBox2.Text + "'" + ", " + "'" + textBox3.Text + "'" + ", " + "'" + textBox4.Text + "'" + "," + "'" + Convert.ToInt16(textBox5.Text) + "'" + "," + "'" + Convert.ToDateTime(dateTimePicker1.Value) + "'" + ")", connect);
cmd.ExecuteNonQuery();
MessageBox.Show("new record added", "Append", MessageBoxButtons.OK, MessageBoxIcon.Information);


}

private void button4_Click(object sender, EventArgs e)
{
cmd = new OleDbCommand("delete from record where snum like" + "'%" + textBox1.Text + "%'", connect);
cmd.ExecuteNonQuery();
MessageBox.Show("record deleted", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

private void button5_Click(object sender, EventArgs e)
{
connect.Close();
this.Close();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//view_click
int row = e.RowIndex;
textBox1.Text = dataGridView1["snum", row].Value.ToString();
textBox2.Text = dataGridView1[1, row].Value.ToString();
textBox3.Text = dataGridView1[2, row].Value.ToString();
textBox4.Text = dataGridView1[3, row].Value.ToString();
textBox5.Text = dataGridView1[4, row].Value.ToString();
dateTimePicker1.Value = DateTime.Parse(dataGridView1[5, row].Value.ToString());
}

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

}

}
}

***********************************************
snum [textbox1 here] (snum stands for student number)
fname [textbox2]
lastname [textbox3]
MI [textbox4]
age [textbox5]
bday [DateTimePicker]

(view button)
(add button)
(delete button)
(close button)

[DataGridView at this area....]


******************this is the Form Format of my program*************

I used MSAccess for the records. The said error was the Argument Exception in this part---> connect = new OleDbConnection(strconnect);

I’m hopeless in this case..

pls help me here…thank you in advance…Ü

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by bcasp
0

Just from quickly looking at your connection string, I saw that you used " marks in your string. You don't actually need these. If you go to http://www.connectionstrings.com, you can get connection strings for various DB platforms. The one they suggest for Access is

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;

If you're not using a password for your database, then just leave the user id as admin and the password blank. Replace the C:\mydatabase.mdb with your actual database location and it should at least get you connected to the database.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.