MySQL Forums
Forum List  »  Optimizer & Parser

insert multiple values from array in mysql database using c#
Posted by: Oliver Danilov
Date: April 21, 2011 12:55AM

Please help,
how can i insert this array to a database faster than this way, do not using "for"



int dolzina=telBroevi.Length;
string[] celBroj = new string[dolzina];
string[] prefix = new string[dolzina];
string[] broj = new string[dolzina];

string MyConString = "SERVER=localhost;" + "DATABASE=np_live;" + "UID=root;" + "PASSWORD=***;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "CREATE TABLE pomosna (broj varchar(9) NOT NULL primary key, prefix varchar(3) NOT NULL DEFAULT 0,ostatok varchar(7) NOT NULL DEFAULT 0)";
connection.Open();
Reader = command.ExecuteReader();
//Reader.Read();
connection.Close();

for (int i = 0; i < telBroevi.Length; i++)
{
celBroj = telBroevi.ToString();
if (telBroevi.ToString().Substring(0, 1) != "2")
{

prefix = telBroevi.ToString().Substring(0, 2);
broj = telBroevi.ToString().Substring(2, 6);

}
else
{
prefix = telBroevi.ToString().Substring(0, 1);
broj = telBroevi.ToString().Substring(1, 7);

}
command.CommandText = "INSERT INTO pomosna(broj, prefix, ostatok)VALUES('" + telBroevi+ "', '" + prefix + "', '" + broj + "');";
connection.Open();
command.ExecuteNonQuery();
// Reader.Read();
connection.Close();
}

Options: ReplyQuote


Subject
Views
Written By
Posted
insert multiple values from array in mysql database using c#
9972
April 21, 2011 12:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.