none
Unknown field exception RRS feed

  • Question

  • Hi there,

    I want to send table data as XML file and import it , for exporting no problems all fields exported succefully but  when i want read file and need to insert to same table  exception raised that xxxx field unknown , that fields has been added lastly is it not binded? but all TableAdapter queries run successfully , i could not know where i can fix this problem


    Thanks


    Esmat

    Thursday, May 4, 2017 10:10 AM

All replies

  • Hello,

    We need to know how you are export/importing. Generally the easy way is to use DataTable methods to read from an xml file and write to an xml file using ReadXml and WriteXml. This can be done by DataTable or DataSet.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, May 4, 2017 11:00 AM
  • Hello,

    We need to know how you are export/importing. Generally the easy way is to use DataTable methods to read from an xml file and write to an xml file using ReadXml and WriteXml.

    Yes exactly <g class="gr_ gr_12 gr-alert gr_tiny gr_spell gr_run_anim ContextualSpelling multiReplace" data-gr-id="12" id="12">i</g>  am using ReadXML and WriteXML

                OpenFileDialog od = new OpenFileDialog();
                od.Filter = "XML Files | *.xml";
                od.InitialDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                if (od.ShowDialog() == DialogResult.OK)
                {
                    ds.ReadXml(od.FileName);
                
    
                foreach (DataTable table in ds.Tables)
                {
                   //Create table
                    foreach (DataRow row in table.Rows)
                    {
                        Trans_ID = Convert.ToInt32(row["Trans_ID"]);
                        ServiceMain_ID = Convert.ToInt32(row["ServiceMain_ID"]);
                        ServiceDetail_ID = Convert.ToInt32(row["ServiceDetail_ID"]);
                        Trans_Date = Convert.ToDateTime(row["Trans_Date"]);
                        Last_Counter = Convert.ToInt32(row["Last_Counter"]);
                        Begining_Counter = Convert.ToInt32(row["Begining_Counter"]);
                        Reading_time = Convert.ToDateTime(row["Reading_Time"]);
                        user_ID = Form1.userID;
                        Well_ID = 1;
                        Drooper_ID = Convert.ToInt32(row["Drooper_ID"]);
                        Day_Cheque = Convert.ToDouble(row["Day_Cheque"]);
                        //Station_ID = Form1.Station_ID;
    
    
                        /*Station_ID is exception field */                  
    
    
                        Station_ID = Convert.ToInt32(row["co_station_ID"]);
                        // I am test reading using MessageBox and reading is working well
                        MessageBox.Show(row["co_station_ID"].ToString());
    
                        cmd = new OleDbCommand();
                        cmd.Parameters.AddWithValue("@Trans_ID", Trans_ID);
                        cmd.Parameters.AddWithValue("@ServiceMain_ID", ServiceMain_ID);
                        cmd.Parameters.AddWithValue("@ServiceDetail_ID", ServiceDetail_ID);
                        cmd.Parameters.AddWithValue("@Trans_Date", Trans_Date.Date);
    
                        cmd.Parameters.AddWithValue("@Last_Counter", Last_Counter);
                        cmd.Parameters.AddWithValue("@Begining_Counter", Begining_Counter);
                        cmd.Parameters.AddWithValue("@Reading_time", Reading_time);
    
                        cmd.Parameters.AddWithValue("@user_ID", user_ID);
                        cmd.Parameters.AddWithValue("@Well_ID", Well_ID);
                        cmd.Parameters.AddWithValue("@Drooper_ID", Drooper_ID);
                        cmd.Parameters.AddWithValue("@Day_Cheque", Day_Cheque);
                        cmd.Parameters.AddWithValue("@co_Station_ID", Station_ID);
    
    
                        cmd.CommandText = @"Insert into tb_DailyTrans_By_Counters(Trans_ID
                                                                                  ,ServiceMain_ID
                                                                                  ,ServiceDetail_ID
                                                                                  ,Trans_Date
                                                                                  ,Last_Counter
                                                                                  ,Begining_Counter
                                                                                  ,Reading_time
                                                                                  ,user_ID
                                                                                  ,Drooper_ID
                                                                                  ,Day_Cheque
                                                                                  ,co_Station_ID) 
                                                         
                                                                                    values
                                                                                  (@Trans_ID
                                                                                  ,@ServiceMain_ID
                                                                                  ,@ServiceDetail_ID
                                                                                  ,@Trans_Date
                                                                                  ,@Last_Counter
                                                                                  ,@Begining_Counter
                                                                                  ,@Reading_time
                                                                                  ,@user_ID
                                                                                  ,@Drooper_ID
                                                                                  ,@Day_Cheque
                                                                                  ,@co_Station_ID)";
                        cmd.Connection = con;
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
    // ,@Well_ID
                        con.Open();
                        cmd.ExecuteReader();
                        con.Close();



    Esmat




    Thursday, May 4, 2017 12:50 PM
  • Hello,

    Sorry for the long time to reply. I'm not seeing the reason for the error.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, May 4, 2017 10:34 PM
  • Hi Karen,

    What is happened that after adding co_Station_ID column i want to reconfigure dataset , when dialog retrieving database information it raises exception of ambiguous outer join ,so instead i built manually my new column in data adapter queries and they are preview data successfully, is there a relate between ambiguous outer join and the exception of Unknown field which attached in previous post?

    Thanks


    Esmat


    Friday, May 5, 2017 7:12 PM

  • Hi Esmat_Halfa,

    Sorry for the late reply.

    According to your question is more related to ADO.NET, I suggest you can visit the ADO.NET forum  for getting suitable help.

    Thanks for your understanding and cooperation.

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 26, 2017 7:22 AM