You must Sign In to post a response.
  • Category: ASP.NET

    Error While saving data from C#.net DataTable to SQL DataTable

    Hi Guys,

    I have a error Table in the sql and in the front end i have datatable in which i save all the error occurs in the application and saves this datatable values to the DB table by passing the front end DataTable to sql dataTable. Its working good in testing environment but not working in Live server and DB and getting the following error.

    "There are not enough fields in the Structured type. Structured types must have at least one field."

    Below is the creation of DataTable in DB and Stored Procudure to save in the error Table from dataTable.

    CREATE TYPE [dbo].[DataTableErrDetails] AS TABLE(
    [ApplicationName] [varchar](300) NULL,
    [ProcessInfo] [varchar](300) NULL,
    [ExceptionDetail] [varchar](max) NULL,
    [FunctionName] [varchar](300) NULL
    )
    GO

    CREATE Procedure [dbo].[USP_InsertErrorDetailsNew]
    @ErrorDetails dbo.DataTableErrDetails READONLY

    AS
    Begin


    INSERT INTO tblAppErrorLog(ApplicationName, ProcessedOn, ProcessInfo,ExceptionDetail,StatusSeqId,FunctionName,UserID)
    SELECT ApplicationName, GETDATE() AS ProcessedOn,
    ProcessInfo,ExceptionDetail,0 AS StatusSeqId,FunctionName ,
    NEWID() AS UserID FROM @ErrorDetails

    END

    Thanks & Regards,
    Rajabharathi
  • #746181
    Hi Rajabharathi,

    Whatever you posted in above not in sync. I mean you posted a different table here and the stored procedure is using different table.
    If it is same then I can see many fields in your insert query which are not present in your table.

    Please provide complete details or complete code. Also try to debug the code and see in which line you are getting this exception.


    Regards,
    Asheej T K

  • #746187
    Yes, as said by asheej there is difference between the table you given and a insert query used.
    Please check the table you have used and the check the field exist in table to insert and columns given in insert query

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #746212
    When are you getting the error.

    the error suggest that you are trying to access/insert value in a table which is either not present or you do not created yet using query.

    Please check that the tables are present before the insert query.

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #746324
    Hi,

    If you want to insert datatable data into database then iterate through out the table then insert it into one by one.


    foreach(DataRow dr in dt.Rows)
    {
    //insert each row into database on here
    }


    Hope this will help you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #761033
    Hi
    Raja

    You can try this Query for your datatbale insert data



    DECLARE @EmpInfoTVP AS EmpDet;
    INSERT INTO @EmpInfoTVP(EMPID,EmpName)
    VALUES (1,'Permenant'),(2,'Temproary'),
    (3,'WestEmployee'),(4,'dEfEtores'),(5,'DefMarketing');
    EXEC InsertEmployeeInfo @EmpInfoTVP;


    Select * from EmployeesIns



    I have attached images given below for datatable insert to table using stored procedure.

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment


  • Sign In to post your comments