|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Failed to convert parameter value from a Guid to a StringI am trying to use the Microsoft Oracle data provider to store a GUID as a string. Get this message: Message: Failed to convert parameter value from a Guid to a String. Inner Message: System.InvalidCastException: Object must implement IConvertible. at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at System.Data.OracleClient.OracleParameter.CoerceValue(Object value, MetaType destinationType)" This does work with the Oracle Data Adapter for Oracle. The field is a varchar2 on the database. We are using a DataAdapter (Oracle) to fill a DataSet with. The DataSet gets set up using a MSSQL DataAdapter. So the dataset have a property to get the GUID value. Getting it from the database into the dataset works fine, but when trying to put the changed DataSet back to the database does not. Our Data Adapter Partial Class ======================= using System; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; using System.Text; using Crown.DaObjects.Connection; using Crown.InterfaceObjects.Types; using Crown.InterfaceObjects.DataSets; namespace Crown.DaObjects.General { public partial class TestGuidDa : BaseDa { public TestGuidDa() { InitializeComponent(); } public TestGuidDa(IContainer container) { container.Add(this); InitializeComponent(); } public TestGuidDa(BaseDb connection) { /// /// Required for Windows.Forms Class Composition Designer support /// InitializeComponent(); Connection = connection; } public TestGuid GetTestGuidDs() { TestGuid testGuidDs = new TestGuid(); Get(sqlDataAdapter1, testGuidDs); return testGuidDs; } public void Put(TestGuid testGuidDs) { Update(sqlDataAdapter1, testGuidDs); } } } Designer Generated method of the DataAdapter =================================== /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.sqlSelectCommand1 = new System.Data.OracleClient.OracleCommand(); this.sqlInsertCommand1 = new System.Data.OracleClient.OracleCommand(); this.sqlUpdateCommand1 = new System.Data.OracleClient.OracleCommand(); this.sqlDeleteCommand1 = new System.Data.OracleClient.OracleCommand(); this.sqlDataAdapter1 = new System.Data.OracleClient.OracleDataAdapter(); // // sqlSelectCommand1 // this.sqlSelectCommand1.CommandText = "TestGuid0"; this.sqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure; this.sqlSelectCommand1.Parameters.AddRange(new System.Data.OracleClient.OracleParameter[] { new OracleParameter("pCUR1",OracleType.Cursor)}); this.sqlSelectCommand1.Parameters["pCUR1"].Direction = System.Data.ParameterDirection.Output; // // sqlInsertCommand1 // this.sqlInsertCommand1.CommandText = "TestGuid_I"; this.sqlInsertCommand1.CommandType = System.Data.CommandType.StoredProcedure; this.sqlInsertCommand1.Parameters.AddRange(new System.Data.OracleClient.OracleParameter[] { new System.Data.OracleClient.OracleParameter("@ABC", System.Data.OracleClient.OracleType.VarChar, 38, "ABC")}); // // sqlUpdateCommand1 // this.sqlUpdateCommand1.CommandText = "TestGuid_U"; this.sqlUpdateCommand1.CommandType = System.Data.CommandType.StoredProcedure; this.sqlUpdateCommand1.Parameters.AddRange(new System.Data.OracleClient.OracleParameter[] { new System.Data.OracleClient.OracleParameter("@ABC", System.Data.OracleClient.OracleType.VarChar, 38, "ABC"), new System.Data.OracleClient.OracleParameter("@Original_ABC", System.Data.OracleClient.OracleType.VarChar, 38, System.Data.ParameterDirection.Input, false, ((byte)(0)), ((byte)(0)), "ABC", System.Data.DataRowVersion.Original, null)}); // // sqlDeleteCommand1 // this.sqlDeleteCommand1.CommandText = "TestGuidD"; this.sqlDeleteCommand1.CommandType = System.Data.CommandType.StoredProcedure; this.sqlDeleteCommand1.Parameters.AddRange(new System.Data.OracleClient.OracleParameter[] { new System.Data.OracleClient.OracleParameter("@Original_ABC", System.Data.OracleClient.OracleType.VarChar, 38, System.Data.ParameterDirection.Input, false, ((byte)(0)), ((byte)(0)), "ABC", System.Data.DataRowVersion.Original, null)}); // // sqlDataAdapter1 // this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1; this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1; this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1; this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "TESTGUID", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("ABC", "ABC")})}); this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1; } The DataSet ========== //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:2.0.50727.42 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ #pragma warning disable 1591 namespace CrownComputing.InterfaceObjects.DataSets { using System; [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "2.0.0.0")] [Serializable()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.ComponentModel.ToolboxItem(true)] [System.Xml.Serialization.XmlSchemaProviderAttribute("GetTypedDataSetSchema")] [System.Xml.Serialization.XmlRootAttribute("TestGuid")] [System.ComponentModel.Design.HelpKeywordAttribute("vs.data.DataSet")] public partial class TestGuid : System.Data.DataSet { private TESTGUIDDataTable tableTESTGUID; private System.Data.SchemaSerializationMode _schemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TestGuid() { this.BeginInit(); this.InitClass(); System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged); base.Tables.CollectionChanged += schemaChangedHandler; base.Relations.CollectionChanged += schemaChangedHandler; this.EndInit(); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected TestGuid(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context, false) { if ((this.IsBinarySerialized(info, context) == true)) { this.InitVars(false); System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler1 = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged); this.Tables.CollectionChanged += schemaChangedHandler1; this.Relations.CollectionChanged += schemaChangedHandler1; return; } string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string)))); if ((this.DetermineSchemaSerializationMode(info, context) == System.Data.SchemaSerializationMode.IncludeSchema)) { System.Data.DataSet ds = new System.Data.DataSet(); ds.ReadXmlSchema(new System.Xml.XmlTextReader(new System.IO.StringReader(strSchema))); if ((ds.Tables["TESTGUID"] != null)) { base.Tables.Add(new TESTGUIDDataTable(ds.Tables["TESTGUID"])); } this.DataSetName = ds.DataSetName; this.Prefix = ds.Prefix; this.Namespace = ds.Namespace; this.Locale = ds.Locale; this.CaseSensitive = ds.CaseSensitive; this.EnforceConstraints = ds.EnforceConstraints; this.Merge(ds, false, System.Data.MissingSchemaAction.Add); this.InitVars(); } else { this.ReadXmlSchema(new System.Xml.XmlTextReader(new System.IO.StringReader(strSchema))); } this.GetSerializationData(info, context); System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged); base.Tables.CollectionChanged += schemaChangedHandler; this.Relations.CollectionChanged += schemaChangedHandler; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.ComponentModel.Browsable(false)] [System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)] public TESTGUIDDataTable TESTGUID { get { return this.tableTESTGUID; } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.ComponentModel.BrowsableAttribute(true)] [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)] public override System.Data.SchemaSerializationMode SchemaSerializationMode { get { return this._schemaSerializationMode; } set { this._schemaSerializationMode = value; } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)] public new System.Data.DataTableCollection Tables { get { return base.Tables; } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)] public new System.Data.DataRelationCollection Relations { get { return base.Relations; } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override void InitializeDerivedDataSet() { this.BeginInit(); this.InitClass(); this.EndInit(); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public override System.Data.DataSet Clone() { TestGuid cln = ((TestGuid)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return cln; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override bool ShouldSerializeTables() { return false; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override bool ShouldSerializeRelations() { return false; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override void ReadXmlSerializable(System.Xml.XmlReader reader) { if ((this.DetermineSchemaSerializationMode(reader) == System.Data.SchemaSerializationMode.IncludeSchema)) { this.Reset(); System.Data.DataSet ds = new System.Data.DataSet(); ds.ReadXml(reader); if ((ds.Tables["TESTGUID"] != null)) { base.Tables.Add(new TESTGUIDDataTable(ds.Tables["TESTGUID"])); } this.DataSetName = ds.DataSetName; this.Prefix = ds.Prefix; this.Namespace = ds.Namespace; this.Locale = ds.Locale; this.CaseSensitive = ds.CaseSensitive; this.EnforceConstraints = ds.EnforceConstraints; this.Merge(ds, false, System.Data.MissingSchemaAction.Add); this.InitVars(); } else { this.ReadXml(reader); this.InitVars(); } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override System.Xml.Schema.XmlSchema GetSchemaSerializable() { System.IO.MemoryStream stream = new System.IO.MemoryStream(); this.WriteXmlSchema(new System.Xml.XmlTextWriter(stream, null)); stream.Position = 0; return System.Xml.Schema.XmlSchema.Read(new System.Xml.XmlTextReader(stream), null); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] internal void InitVars() { this.InitVars(true); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] internal void InitVars(bool initTable) { this.tableTESTGUID = ((TESTGUIDDataTable)(base.Tables["TESTGUID"])); if ((initTable == true)) { if ((this.tableTESTGUID != null)) { this.tableTESTGUID.InitVars(); } } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] private void InitClass() { this.DataSetName = "TestGuid"; this.Prefix = ""; this.Namespace = "http://tempuri.org/TestGuid.xsd"; this.EnforceConstraints = true; this.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; this.tableTESTGUID = new TESTGUIDDataTable(); base.Tables.Add(this.tableTESTGUID); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] private bool ShouldSerializeTESTGUID() { return false; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] private void SchemaChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e) { if ((e.Action == System.ComponentModel.CollectionChangeAction.Remove)) { this.InitVars(); } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) { TestGuid ds = new TestGuid(); System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType(); System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence(); xs.Add(ds.GetSchemaSerializable()); System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; return type; } public delegate void TESTGUIDRowChangeEventHandler(object sender, TESTGUIDRowChangeEvent e); [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "2.0.0.0")] [System.Serializable()] [System.Xml.Serialization.XmlSchemaProviderAttribute("GetTypedTableSchema")] public partial class TESTGUIDDataTable : System.Data.DataTable, System.Collections.IEnumerable { private System.Data.DataColumn columnABC; [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TESTGUIDDataTable() { this.TableName = "TESTGUID"; this.BeginInit(); this.InitClass(); this.EndInit(); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] internal TESTGUIDDataTable(System.Data.DataTable table) { this.TableName = table.TableName; if ((table.CaseSensitive != table.DataSet.CaseSensitive)) { this.CaseSensitive = table.CaseSensitive; } if ((table.Locale.ToString() != table.DataSet.Locale.ToString())) { this.Locale = table.Locale; } if ((table.Namespace != table.DataSet.Namespace)) { this.Namespace = table.Namespace; } this.Prefix = table.Prefix; this.MinimumCapacity = table.MinimumCapacity; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected TESTGUIDDataTable(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { this.InitVars(); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public System.Data.DataColumn ABCColumn { get { return this.columnABC; } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.ComponentModel.Browsable(false)] public int Count { get { return this.Rows.Count; } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TESTGUIDRow this[int index] { get { return ((TESTGUIDRow)(this.Rows[index])); } } public event TESTGUIDRowChangeEventHandler TESTGUIDRowChanging; public event TESTGUIDRowChangeEventHandler TESTGUIDRowChanged; public event TESTGUIDRowChangeEventHandler TESTGUIDRowDeleting; public event TESTGUIDRowChangeEventHandler TESTGUIDRowDeleted; [System.Diagnostics.DebuggerNonUserCodeAttribute()] public void AddTESTGUIDRow(TESTGUIDRow row) { this.Rows.Add(row); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TESTGUIDRow AddTESTGUIDRow(System.Guid ABC) { TESTGUIDRow rowTESTGUIDRow = ((TESTGUIDRow)(this.NewRow())); rowTESTGUIDRow.ItemArray = new object[] { ABC}; this.Rows.Add(rowTESTGUIDRow); return rowTESTGUIDRow; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TESTGUIDRow FindByABC(System.Guid ABC) { return ((TESTGUIDRow)(this.Rows.Find(new object[] { ABC}))); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public virtual System.Collections.IEnumerator GetEnumerator() { return this.Rows.GetEnumerator(); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public override System.Data.DataTable Clone() { TESTGUIDDataTable cln = ((TESTGUIDDataTable)(base.Clone())); cln.InitVars(); return cln; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override System.Data.DataTable CreateInstance() { return new TESTGUIDDataTable(); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] internal void InitVars() { this.columnABC = base.Columns["ABC"]; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] private void InitClass() { this.columnABC = new System.Data.DataColumn("ABC", typeof(System.Guid), null, System.Data.MappingType.Element); base.Columns.Add(this.columnABC); this.Constraints.Add(new System.Data.UniqueConstraint("Constraint1", new System.Data.DataColumn[] { this.columnABC}, true)); this.columnABC.AllowDBNull = false; this.columnABC.Unique = true; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TESTGUIDRow NewTESTGUIDRow() { return ((TESTGUIDRow)(this.NewRow())); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override System.Data.DataRow NewRowFromBuilder(System.Data.DataRowBuilder builder) { return new TESTGUIDRow(builder); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override System.Type GetRowType() { return typeof(TESTGUIDRow); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override void OnRowChanged(System.Data.DataRowChangeEventArgs e) { base.OnRowChanged(e); if ((this.TESTGUIDRowChanged != null)) { this.TESTGUIDRowChanged(this, new TESTGUIDRowChangeEvent(((TESTGUIDRow)(e.Row)), e.Action)); } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override void OnRowChanging(System.Data.DataRowChangeEventArgs e) { base.OnRowChanging(e); if ((this.TESTGUIDRowChanging != null)) { this.TESTGUIDRowChanging(this, new TESTGUIDRowChangeEvent(((TESTGUIDRow)(e.Row)), e.Action)); } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override void OnRowDeleted(System.Data.DataRowChangeEventArgs e) { base.OnRowDeleted(e); if ((this.TESTGUIDRowDeleted != null)) { this.TESTGUIDRowDeleted(this, new TESTGUIDRowChangeEvent(((TESTGUIDRow)(e.Row)), e.Action)); } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override void OnRowDeleting(System.Data.DataRowChangeEventArgs e) { base.OnRowDeleting(e); if ((this.TESTGUIDRowDeleting != null)) { this.TESTGUIDRowDeleting(this, new TESTGUIDRowChangeEvent(((TESTGUIDRow)(e.Row)), e.Action)); } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public void RemoveTESTGUIDRow(TESTGUIDRow row) { this.Rows.Remove(row); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs) { System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType(); System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence(); TestGuid ds = new TestGuid(); xs.Add(ds.GetSchemaSerializable()); System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "TESTGUIDDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; return type; } } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "2.0.0.0")] public partial class TESTGUIDRow : System.Data.DataRow { private TESTGUIDDataTable tableTESTGUID; [System.Diagnostics.DebuggerNonUserCodeAttribute()] internal TESTGUIDRow(System.Data.DataRowBuilder rb) : base(rb) { this.tableTESTGUID = ((TESTGUIDDataTable)(this.Table)); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public System.Guid ABC { get { return ((System.Guid)(this[this.tableTESTGUID.ABCColumn])); } set { this[this.tableTESTGUID.ABCColumn] = value; } } } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "2.0.0.0")] public class TESTGUIDRowChangeEvent : System.EventArgs { private TESTGUIDRow eventRow; private System.Data.DataRowAction eventAction; [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TESTGUIDRowChangeEvent(TESTGUIDRow row, System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public TESTGUIDRow Row { get { return this.eventRow; } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] public System.Data.DataRowAction Action { get { return this.eventAction; } } } } } #pragma warning restore 1591 Thanks Was this post helpful to you? Why should I rate a post? Expand AllCollapse All Manage Your Profile |Legal |Contact Us |MSDN Flash Newsletter Is there any workaround or fix? thanks |
|||||||||||||||||||||||