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)

___________________
l l
l l (this is the DataGridView)
l l
l l
l l
l l
------------------------------


******************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…Ü


******************************************
i already erased the "" inner mark here.. -->

static string strconnect = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Documents and Settings\avupdate\My Documents\db3.mdb";

so it turns out to be like this...

static string strconnect = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\avupdate\My Documents\db3.mdb";

but the problem now is this...

the message box saying "bukas na ang database" keeps popping out even if i keep clicking the "ok" button, it still pops out... and the form won't show....='(

Funny... You are launching a new form1 inside your onLoad handler. Each one has this dialog, and each one launches another form1... a logical never ending loop. (until you run out of resources :)


// Jerry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.