Alan Joyce

Alan Joyce

  • NA
  • 3
  • 0

Placing Data from a Dataset table directly into SQL

Nov 26 2009 11:37 AM

Hi, I'm trying to place table data that's returned from a webservice method into an SQL table. The table is configured the same was as the returned data table in the dataset.
The code i'm using is below, the dataset containing the data is called pDs and the table i'm trying to insert the data into is called ALAN_BusinessReports_EPIC
This code runs without any errors but the table in the database doesn't get updated.
 
try

{
   SqlConnection conn = new SqlConnection("Server=IELETT3KA05;database=Metrics;uid=webuser;pwd=userweb");

   if (conn.State != ConnectionState.Open)
      conn.Open();
   
   DataSet tmpDs = new DataSet();
   SqlDataAdapter pDa = new SqlDataAdapter("Select * from ALAN_BusinessReports_EPIC", conn);
 
   pDa.FillSchema(tmpDs,
SchemaType.Source, pDs.Tables[0].TableName);
   pDa.Fill(tmpDs, 0, pDs.Tables[0].Rows.Count, pDs.Tables[0].TableName);

 
   SqlCommandBuilder pCbm = new SqlCommandBuilder(pDa);

 
   pDa.InsertCommand = pCbm.GetInsertCommand();
 
   pDa.Update(pDs, pDs.Tables[0].TableName);
 
   conn.Close();
}
 
catch (Exception ex2)
{
   Response.Write(ex2.Message);
}

Answers (1)