Friday, March 4, 2011

xml format

private bool fnBulkInsFilterISBN(DataTable dt, string sPID, ref string sErrorMessage)
{
bool blnResult = false;
DataSet ds = new DataSet();
if (dt != null)
{
ds.Tables.Clear();
ds.Tables.Add(dt.Copy());

ds.Tables[0].TableName = "InventoryDetails";

dt = ds.Tables[ds.Tables[0].TableName];

if (dt.Rows.Count > 0)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(1000);
System.IO.StringWriter sw = new System.IO.StringWriter(sb);

foreach (DataColumn col in dt.Columns)
{
col.ColumnMapping = MappingType.Attribute;
}

ds.WriteXml(sw, System.Data.XmlWriteMode.WriteSchema);



SqlConnection ConVMSServer;
SqlCommand cmdVMSInsertlog;

ConVMSServer = new SqlConnection(strServerConnection);
if (ConVMSServer.State == ConnectionState.Closed) { ConVMSServer.Open(); }

int intRecordsAffected = 0;
try
{
cmdVMSInsertlog = new SqlCommand("Usp_VMSInvSearchBulkInsert", ConVMSServer);
cmdVMSInsertlog.CommandTimeout = 0;
cmdVMSInsertlog.CommandType = CommandType.StoredProcedure;
cmdVMSInsertlog.Parameters.AddWithValue("@ID", sPID);
cmdVMSInsertlog.Parameters.AddWithValue("@empdata", SqlDbType.NText).Value = sb.ToString();

intRecordsAffected = cmdVMSInsertlog.ExecuteNonQuery();
if (intRecordsAffected > 0) { blnResult = true; }
}
catch (Exception ex)
{
SetErrorMsg(ex.Message);

}
finally
{

if (ConVMSServer.State == ConnectionState.Open) { ConVMSServer.Close(); }

ConVMSServer.Dispose();

}

}




}
return blnResult;
}

No comments:

Post a Comment