I tried to insert excel data to database, MS SQL.
Currently I looped the excel records and insert. It took too long.
Is there any way to insert excel records to database once ?
Thanks and Regards,
Here is my code:
User user = new User();
cmd_obj = new OleDbCommand("SELECT * FROM [Sheet1$]", con_obj);
OleDbDataReader dr = cmd_obj.ExecuteReader();
while (dr.Read())
{
int blnBadSyntax = 0;
int blnBadDomain = 0;
int blnBadSMTP = 0;
int blnGreylisted = 0;
int blnBadMailbox = 0;
bool blnIsValid = false;
string key = "2CH3W-7ENLC-FWLZ4-WEUVY-JRQ11-AU69U-W63V5-ULF1C-DA5RC-RU7XS-XK6JY-6JT5U-MYLX";
MXValidate.LoadLicenseKey(key);
MXValidate mx = new MXValidate();
mx.LogInMemory = true;
mx.CheckLiteralDomain = true;
mx.CheckGreylisting = true;
try
{
MXValidateLevel level = mx.Validate(user.StrEmailId, MXValidateLevel.Mailbox);
switch (level)
{
case MXValidateLevel.NotValid:
blnBadSyntax = 1;
break;
case MXValidateLevel.Syntax:
blnBadDomain = 1;
break;
case MXValidateLevel.MXRecords:
blnBadSMTP = 1;
break;
case MXValidateLevel.SMTP:
blnGreylisted = 1;
blnIsValid = true;
break;
case MXValidateLevel.Greylisted:
blnBadMailbox = 1;
blnIsValid = true;
break;
case MXValidateLevel.Mailbox:
blnIsValid = true;
break;
}
user.BlnBadSyntax = blnBadSyntax;
user.BlnBadDomain = blnBadDomain;
user.BlnBadSMTP = blnBadSMTP;
user.BlnGraylisted = blnGreylisted;
user.BlnBadMailBox = blnBadMailbox;
if (blnIsValid)
{
user.StrStatus = "Valid";
}
else
{
user.StrStatus = "InValid";
logFile.writeLog(mx.GetLog());
}
}
catch (DnsException ex)
{
logFile.writeLog(mx.GetLog());
}
InsertuserDetails(user);
}