Click to See Complete Forum and Search --> : [RESOLVED] ms access insert data question


marvin2k5
July 25th, 2009, 08:06 AM
heyall, i got this code that grabs information from a data base and shows it in a listbox:

my questions are how can you insert data to the table? ( iknow that in sql its something like this
sql = "insert into tablename(username,password)values(123,123)")

and is there a better way to show the data(that it will be more tidy?

thanks, Marvin

marvin2k5
July 25th, 2009, 08:08 AM
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;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btn_Click(object sender, EventArgs e)
{
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;

Myconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=C:\Documents and Settings\Administrator\Desktop\מחסן2010\lala.mdb");
Myconnection.Open();

OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT * FROM equipment";
dbReader = cmd.ExecuteReader();

int id;
string name;
int number;
string returned;

while(dbReader.Read())
{
id = (int)dbReader.GetValue(0);
name = (string)dbReader.GetValue(3);
number = (int)dbReader.GetValue(2);
returned = (string)dbReader.GetValue(1);

lb.Items.Add(id + " " + name + " " + number + " " + returned);

}

dbReader.Close();
Myconnection.Close();
}

dglienna
July 25th, 2009, 12:50 PM
Download the 101 Samples (http://go.internet.com/?id=474X1058&url=http%3A//code.msdn.microsoft.com/vbsamples/) and take a look at some of the DB programs.

marvin2k5
July 25th, 2009, 03:44 PM
thanks alot, i found my answer there