CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    3

    [RESOLVED] ms access insert data question

    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
    Last edited by marvin2k5; July 25th, 2009 at 03:45 PM.

  2. #2
    Join Date
    Jul 2009
    Posts
    3

    Re: ms access insert data question

    Code:
    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();
    }

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: ms access insert data question

    Download the 101 Samples and take a look at some of the DB programs.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2009
    Posts
    3

    Re: ms access insert data question

    thanks alot, i found my answer there

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured