kagomex

kagomex

  • NA
  • 1
  • 0

Inserting Data into Database Using Loop?

Jul 13 2005 4:10 AM

I am thinking if it is possible to insert multipe rows of Data in one shot?

The code I trying to use but cannot seen working,Data1 is the name of one list of input that can be insert by the user(List Box) :

String connect= "Provider=Microsoft.JET.OLEDB.4.0;"+@"data source=c:\Some.mdb";

OleDbConnection con= new OleDbConnection(connect);

con.Open();

OleDbCommand cmd =con.CreateCommand();

OleDbParameter Casep1;

for(int i=0;i<Data1.Items.Count;i++)

{

Data1.SelectedIndex=i;

cmd.CommandText= "INSERT INTO Example VALUES(?)";

Casep1 = new OleDbParameter();

Casep2.Value=Data1.Text.Substring(0,10).Trim();

cmd.Parameters.Add(Casep1);

cmd.ExecuteNonQuery();

}

con.Close();


Answers (3)