how to insert data using arraylist into ms access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • furafura
    New Member
    • Mar 2010
    • 1

    how to insert data using arraylist into ms access

    How can i insert many data using arraylist in c# and save all the data in database .mdb file ?

    How can i add arraylist in name, latitude and longitude so these three things user can input many data on it and save the data in database?

    Here is my code:
    Code:
     string myConnectionString = "";
    
    
                myConnectionString = "Provider =Microsoft.Jet.OLEDB.4.0; Data Source=E:\\Placemark.mdb";
    
                OleDbConnection myConnection = new OleDbConnection(myConnectionString);
    
                string myInsertQuery = "INSERT INTO placemark " + "(Name, Latitude, Longitude)" + "VALUES(@Name, @Latitude, @Longitude)";
    
    
                OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
    
                myCommand.Connection = myConnection;
    
             
    
    	myCommand.CommandText = myInsertQuery;
    	myCommand.CommandType = CommandType.Text;
    
    	myCommand.Parameters.Add("Name", OleDbType.Char).Value = textBoxPlacemark.Text;
    	myCommand.Parameters.Add("Latitude", OleDbType.Char).Value = latitude.Text;
    	myCommand.Parameters.Add("Longitude", OleDbType.Char).Value = longitude.Text;
    
                   
                myConnection.Open();
                try
                {
    
                    //reader = myCommand.ExecuteReader();
                    myCommand.ExecuteNonQuery();
    
                    MessageBox.Show("record are successful insert");
                }
    
                catch (Exception ex)
                {
    
                    MessageBox.Show(ex.Message.ToString());
                }
    
                myConnection.Close();
    
            }
    
            private void HandleConnection(OleDbConnection myConnection)
            {
                throw new NotImplementedException();
            }
        }
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    write multiple insert statements and pass in as a OLedb Transaction

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Database How-to parts 1 and 2
      Database tutorial Part 1
      Database tutorial Part 2

      Comment

      Working...