473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

No mapping exists from object type ... to a known managed provider native type.

Please Help! I am a System Developer at a private company and I encounter this error while I was playing at my codes. I am using Visual Studio 2010 and my database is MSSQL 2008 R2. I keep on searching on the net for the answer but I failed. Please help me with this one and Thank you in advance.

The process is so simple that is only to populate the datagridview with data then save it to the database. Then on the process of saving the data, I encounter an error message “No mapping exists from object type SLI_Payroll.DataSetLibrary+DTContactsDataTable to a known managed provider native type.”

The data of the datagridview will be transfered to a dataset datatable. The dataset is not hard code and it was added as a New Item.

Sorry but i will put the whole code of the form.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class frmContacts
  3.     '------------------------------------------------------------------------------------
  4.     Private Function sp_Contacts(ByVal DT As DataTable)
  5.  
  6.         zResultReturnBoolean = Nothing
  7.  
  8.         Try
  9.  
  10.             zCommand = SetSQLCommand("sp_tabContacts")
  11.  
  12.             CON.Open()
  13.  
  14.             With zCommand.Parameters
  15.                 .AddWithValue("@DT", DT)
  16.             End With
  17.  
  18.             zCommand.CommandType = CommandType.StoredProcedure
  19.             If zCommand.ExecuteNonQuery() = 0 Then : zResultReturnBoolean = False : Else : zResultReturnBoolean = True : End If
  20.  
  21.             CON.Close()
  22.  
  23.         Catch ex As Exception
  24.             CON.Close()
  25.             MessageBox.Show(ex.Message, "SQL Error!")
  26.             zResultReturnBoolean = False
  27.         End Try
  28.  
  29.         Return zResultReturnBoolean
  30.  
  31.     End Function
  32.     '------------------------------------------------------------------------------------
  33.     Private Sub frmContacts_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  34.  
  35.         Call TempDataTable()
  36.  
  37.     End Sub
  38.     '------------------------------------------------------------------------------------
  39.     Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click, btnSave.Click
  40.  
  41.         Select Case sender.name
  42.             Case btnClose.Name
  43.                 Me.Close()
  44.             Case btnSave.Name
  45.                 Call SaveProcedure()
  46.         End Select
  47.  
  48.     End Sub
  49.     '------------------------------------------------------------------------------------
  50.     Private Sub SaveProcedure()
  51.  
  52.         Dim DTContacts As New DataSetLibrary.DTContactsDataTable
  53.  
  54.         For Each dgRow As DataGridViewRow In dgList.Rows
  55.  
  56.             '--Solution 1---
  57.             DTContacts.AddDTContactsRow(Val(dgRow.Cells(c_ID.Index).Value),
  58.                                         dgRow.Cells(c_name.Index).Value,
  59.                                         Format(CDate(dgRow.Cells(c_bday.Index).Value), "MM/dd/yyyy"),
  60.                                         dgRow.Cells(c_address.Index).Value,
  61.                                         dgRow.Cells(c_telNo.Index).Value)
  62.             '---------------
  63.  
  64.             ''--Solution 2---
  65.             'zTempDataTable.Rows.Add(Val(dgRow.Cells(c_ID.Index).Value),
  66.             '                            dgRow.Cells(c_name.Index).Value,
  67.             '                            Format(CDate(dgRow.Cells(c_bday.Index).Value), "MM/dd/yyyy"),
  68.             '                            dgRow.Cells(c_address.Index).Value,
  69.             '                            dgRow.Cells(c_telNo.Index).Value)
  70.             ''---------------
  71.         Next
  72.         '--solution 1
  73.         If sp_Contacts(DTContacts) Then
  74.             ''--solution 2
  75.             'If sp_Contacts(zTempDataTable) Then
  76.             MessageBox.Show("Successfully Saved!")
  77.         End If
  78.  
  79.     End Sub
  80.     '------------------------------------------------------------------------------------
  81.     Private Sub DisplayRecord()
  82.  
  83.         Dim DT As New DataTable
  84.         DT = GetDataTable("SELECT * FROM tabContacts A ORDER BY A.ID")
  85.  
  86.         dgList.Rows.Clear()
  87.         For Each dRow As DataRow In DT.Rows
  88.  
  89.             dgList.Rows.Add()
  90.             With dgList.Rows(dgList.RowCount - 1)
  91.  
  92.                 .Cells(c_ID.Index).Value = Val(dRow.Item("ID").ToString)
  93.                 .Cells(c_name.Index).Value = dRow.Item("name").ToString
  94.                 .Cells(c_bday.Index).Value = Format(CDate(dRow.Item("bday").ToString), "MM/dd/yyyy")
  95.                 .Cells(c_address.Index).Value = dRow.Item("address").ToString
  96.                 .Cells(c_telNo.Index).Value = dRow.Item("telno").ToString
  97.  
  98.             End With
  99.  
  100.         Next
  101.  
  102.     End Sub
  103.     '------------------------------------------------------------------------------------
  104.     Public Sub TempDataTable()
  105.  
  106.         zTempDataTable = New DataTable
  107.  
  108.         With zTempDataTable.Columns
  109.             .Add(New DataColumn("ID", GetType(Integer)))
  110.             .Add(New DataColumn("name", GetType(String)))
  111.             .Add(New DataColumn("bday", GetType(DateTime)))
  112.             .Add(New DataColumn("address", GetType(String)))
  113.             .Add(New DataColumn("telno", GetType(String)))
  114.         End With
  115.  
  116.     End Sub
  117.  
  118. End Class
  119.  
  120.  
  121.  
This is the code of my SQL

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE TABLE [dbo].[tabContacts](
  3.     [ID] [int] NOT NULL,
  4.     [name] [varchar](50) NULL,
  5.     [bday] [date] NULL,
  6.     [address] [varchar](50) NULL,
  7.     [telno] [nchar](10) NULL,
  8.  CONSTRAINT [PK_tabContacts] PRIMARY KEY CLUSTERED 
  9. (
  10.     [ID] ASC
  11. )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  12. ) ON [PRIMARY]
  13. '------------------------------------------------------------------------------------
  14. CREATE PROCEDURE [dbo].[sp_tabContacts] 
  15.  
  16.     @DT dbo.type_tabContacts READONLY
  17. AS
  18. BEGIN
  19.  
  20.     SET NOCOUNT ON;
  21.  
  22.     MERGE INTO tabContacts as A
  23.         USING(SELECT ID,name,bday,address,telno
  24.                             FROM @DT) AS B
  25.  
  26.             ON A.ID = B.ID
  27.  
  28.             WHEN MATCHED THEN
  29.  
  30.                     UPDATE SET 
  31.                         A.name = B.name,
  32.                         A.bday = B.bday,
  33.                         A.address = B.address,
  34.                         A.telno = B.telno
  35.  
  36.             WHEN NOT MATCHED THEN
  37.  
  38.                     INSERT
  39.                     (
  40.                         ID,name,bday,address,telno
  41.                     )
  42.                     VALUES
  43.                     (
  44.                         B.ID,B.name,B.bday,B.address,B.telno
  45.                     );        
  46.  
  47. END
  48. '------------------------------------------------------------------------------------
  49. CREATE TYPE [dbo].[type_tabContacts] AS TABLE(
  50.     [ID] [int] NOT NULL,
  51.     [name] [varchar](50) NULL,
  52.     [bday] [date] NULL,
  53.     [address] [varchar](50) NULL,
  54.     [telno] [varchar](10) NULL,
  55.     PRIMARY KEY CLUSTERED 
  56. (
  57.     [ID] ASC
  58. )WITH (IGNORE_DUP_KEY = OFF)
  59. )
  60. GO
  61.  
  62.  
  63.  
But if you will remove the comment at solution 2 then comment solution 1. The saving will be successful.

Please help
Sep 2 '13 #1
0 1952

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ramesh | last post by:
hi all, Where i can get the download version of ".Net Managed Provider for Oracle 1.1". Actually i want to install latest version of Mtxoci.dll. I have tried to download from...
1
by: Ramesh | last post by:
hi, I just want to know the difference between ".Net Framework Managed Provider for Oracle" and ".Net Managed Provider for Oracle 1.1". Can anybody knows about this details. ".Net Managed...
4
by: m96 | last post by:
hi, i'm trying to make a query to a ldap server (version v2 or v3 doen't matter) with c#. the query works just fine but the problem is that i can't read the custom attributes/fields, since .net...
0
by: Stefan | last post by:
Hi, Could anyone share some light on this and how I can work around it. If I have 2 managed c++ dlls (A and B) and B tries to use a native class in A this fails to link. It is easily...
0
by: pagates | last post by:
Hello All, I am having a problem using an ODBC connection after loading the .NET Managed Provider for Oracle from the Microsoft website. I get one of the "Send Report To Microsoft" dialogs. ...
2
by: aarepasky | last post by:
I am getting the the message on the command: cm.ExecuteNonQuery(); Complete message is: No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider...
0
by: gigi.lagria | last post by:
I am getting the following error only on pages that contain a SqlDateSource (all other pages pull data fine). Access to the ADO.net Managed Provider 'SqlClientFactory' was denied in the data...
0
by: macrel | last post by:
Just want to provide a work around to the following message: Access to the ADO.net Managed Provider 'SqlClientFactory' was denied in the data source with ID 'SqlDataSource1' because of security...
2
by: Joe | last post by:
I am trying to get a good understanding of these concepts and how they apply to code and classes (possibly different). As well as MSIL and Native Code (x86 assembly). To facilitate discussion...
0
by: ort11 | last post by:
Hi All. Well, I have been trying a few things to solve this problem, but please let me set the sage first. I have a .net 2005 class lib in C++ that is using fastdelegates to wrap a VC6 DLL that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.