Newb Question....Database Entry Form

U

uluvale96799

Hi,

I'm very new to programming so forgive me for asking the dumb question.
I'm trying to develop a database application using c#, and I'm using
the northwind database. I'm currently using visual c# express edition
2005 as well as sql 2005 express.

Here's the thing I've been trying to figure out. I want to insert a new
row in the Employees Table when I click a button called btnAdd. When I
was learning delphi, I would just put the dataset into insert mode for
instance dataset.insert.

How can I achieve this in visual c# I'm wondering. Here's my code.

Please, let me know if there's anymore details I can give. I usually
find the solution by googling it, but I've been stuck on this for a
while.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Northwind
{
public partial class frmEmployeeDB : Form
{
public frmEmployeeDB()
{
InitializeComponent();
}

/* private void frmEmployeeDB_Load(object sender, EventArgs e)
{
NORTHWNDDataSet.EmployeesRow newEmployeesRow;
newEmployeesRow = NORTHWNDDataSet
}*/

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

private void btnAdd_Click(object sender, EventArgs e)
{
NORTHWNDDataSetTableAdapters.EmployeesTableAdapter
employeeTableAdapter =
new
Northwind.NORTHWNDDataSetTableAdapters.EmployeesTableAdapter();

employeeTableAdapter.Insert();
}

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

this.employeesTableAdapter.Fill(this.nORTHWNDDataSet.Employees);

}



/* private void bindingSource1_CurrentChanged(object sender,
EventArgs e)
{

}*/
}
}



Thanks,


Charles
 
G

Guest

Hi

In your code when you click the button (btnAdd_Click) you are creating an
object and inserting a new row..

Create the object in the class when it loads (that means just one time), and
just leave the employeeTableAdapter.Insert() method inside the btnAdd_Click

BTW the Insert() method takes some arguments, those are the fields from the
table the TableAdapter is referenced (in this case Employees table), so you
may need to pass the values to insert in that table.

I did this one time in an app, i'm not an expert on the subject, but i hope
this helps you :)
 
C

Charles

Thanks alot as soon as I get to my computer I'll look into this..

Again, thanks for the tip.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top