SAMPLE CODE
The values are EXTRACTED from the XML FILE and LOADED values into the DATABASE TABLE.
private
void ReadXMlfile()
{
try
{
int
c = 0;
int
c1 = 0;
string
Presentation = "";
string
Staff = "";
string
Company = "";
string
Customer = "";
string
EmployeeNo="";
string
Rec_Date = "";
string
Rec_Time = "";
string
TotalTimeSpent = "";
string
EmailId = "";
string
Place = "";
string
PhoneNo = "";
string
Feedback_App = "";
string
P_time = "";
string
LeadNo = "";
string
Lead_Type = "";
string
Closed_status = "";
string
Branch_Name = "";
// object StrVal;
// string StrVal12;
string strFileName;
//SavePath=ConfigurationSettings.AppSettings["ServerPath"];
----------------------------------------------------------
Path is assigning in the strFileName
----------------------------------------------------------
strFileName="C://Inetpub/wwwroot/eMarTrackServer/ReadXML";
//strFileName=SavePath+"/ReadXML";
DataSet myDataSet = new DataSet();
//myDataSet.ReadXml(strFileName);
---------------------------------------------------------
Assigning the variable which has a value to the Array Variable
---------------------------------------------------------
string[] FilePath= Directory.GetFiles(strFileName);
-------------------------------------------------------------
By using the for loop we are retrieving the each file from the corresponding folder
----------------------------------------------------------
foreach(string Element in FilePath)
{
myDataSet.ReadXml(Element);
Con= new SqlConnection(StrConnection);
foreach
(DataTable thisTable in myDataSet.Tables)
{
foreach
(DataRow myRow in thisTable.Rows)
{
foreach (DataColumn myCol in thisTable.Columns)
{
if (c == 0)
{
Presentation = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if (c == 1)
{
Staff = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1); }
else
{
if
(c == 2)
{
Company = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if
(c == 3)
{
Customer = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if
(c == 4)
{
EmployeeNo = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if
(c == 5)
{
Rec_Date = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if
(c == 6)
{
Rec_Time = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if
(c == 7)
{
TotalTimeSpent = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if (c == 8)
{
EmailId = myRow[myCol].ToString();
//Question_No = QM_ID;
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
c1 = 0;
}
else
{
if (c == 9)
{
Place = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if (c == 10)
{
PhoneNo = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(ref c), c - 1);
}
else
{
if
(c == 11)
{
Feedback_App = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(
ref c), c - 1);
}
else
{
if (c == 12)
{
P_time = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(
ref c), c - 1);
}
else
{
if
(c == 13)
{
LeadNo = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(
ref c), c - 1);
}
else
{
if (c == 14)
{
Lead_Type = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(
ref c), c - 1);
}
else
{
if (c == 15)
{
Closed_status = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(
ref c), c - 1);
}
else
{
if
(c == 16)
{
Branch_Name = myRow[myCol].ToString();
System.Math.Min(System.Threading.Interlocked.Increment(
ref c), c - 1);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
string StrQueryValue;
if(Con.State==ConnectionState.Open)
{
Con.Close();
}
Con.Open();
--------------------------------------------------------------
Inserting the values into the table what are all retrieved from the XML FILE
StrQueryValue="insert into Report(PresentationName,StaffName,Company,CustomerName,EmployeeID,R_Date,R_Time,TotalTime,Email,Location,PhoneNo1,PhoneNo2,PhoneNo3,Feedback,Ptime,LeadId,LeadType,Closed,BrName) values('" +Presentation.Trim() +"','"+ Staff.Trim() +"','"+Company.Trim() +"','" + Customer.Trim() + "','" + EmployeeNo.Trim() + "','" + Rec_Date.Trim() +"','" + Rec_Time.Trim() +"','"+ TotalTimeSpent.Trim() + "','"+ EmailId.Trim() +"','" + Place.Trim() +"','"+ PhoneNo.Trim() +"','"+ Feedback_App.Trim() +"','" + P_time.Trim() +"','"+ LeadNo.Trim() +"','"+ Lead_Type.Trim() +"','"+ Closed_status.Trim() +"','" + Branch_Name.Trim() +"')";
Cmd=
new SqlCommand(StrQueryValue,Con);
Cmd.ExecuteNonQuery();
Con.Close();
}
}
----------------------------------------------------------------
After inserting the values into the table here we are deleting the
XML file, which is in the folder
----------------------------------------------------------------
File.Delete(Element);
// Element is the variable which it
}
}
catch(Exception ex)
{
//Response.Write(ex);
}
}