[Mono-list] GetUpdateCommand/ExecuteNonQuery adapter.Update

Wolfgang Mauer W.Mauer at top-soft.info
Wed Dec 10 04:20:27 EST 2008


Thanks for Help.
Now i use the factory from System.Data.
adapter.Update updates 0 records (values are changed!)
GetUpdateCommand throws a cast exception.
Now i write my own UpdateCommand :-((
something like this

public static DbCommand CreateUpdateCommand(DbProviderFactory factory, DataSet 
dataSet)
		{
			DbCommand updateCommand = factory.CreateCommand();
			if (dataSet.Tables.Count > 1)
			{
				throw new InvalidOperationException("Nur eine Tabelle pro DataSet 
erlaubt!");
			}
			DataTable table = dataSet.Tables[0];
			string commandText = String.Format("UPDATE `{0}` SET", table.TableName);
			string whereText = " WHERE";

			foreach (DataColumn column in table.Columns)
			{
				if (column.Unique)
				{
					whereText += String.Format(" `{0}` = ?{0}", column.ColumnName);
				}
				else
				{
					commandText += String.Format(" `{0}` = ?{0},", column.ColumnName);
				}
				DbParameter param = factory.CreateParameter();
				param.ParameterName = column.ColumnName;
				param.DbType = TypeConvertor.ToDbType(column.DataType);
				param.Value = dataSet.Tables[0].Rows[0][column.ColumnName];
				updateCommand.Parameters.Add(param);
			}
			commandText = commandText.Remove(commandText.Length -1);
			updateCommand.CommandText = commandText + whereText;
			return updateCommand;
		}

/Wolfgang

>Am Dienstag, 9. Dezember 2008 15:35:06 schrieb Daniel Morgan:
> If you are using gmcs and the .net 2.0 profile or higher, you should be
> using the built-in provider factories in System.Data.
>
> You would only use the provider factory stuff from Mono.Data if you are
> using mcs and the .net  1.1 profile.  Mono.Data.ProviderFactory is
> deprecated and should only be used with .net 1.1 software.
>
> DbcommandBuilder does not exist in the .net 1.1 profile.  DbCommandBuilder
> is a data type found in the .net 2.0 profile; therefore, you should be
> using the gmcs to compile and DbProviderFactory found in System.Data.
>
> http://msdn.microsoft.com/en-us/library/dd0w4a2z.aspx
>
> --- On Tue, 12/9/08, Wolfgang Mauer <W.Mauer at top-soft.info> wrote:
> > From: Wolfgang Mauer <W.Mauer at top-soft.info>
> > Subject: [Mono-list]  GetUpdateCommand/ExecuteNonQuery adapter.Update
> > To: mono-list at lists.ximian.com
> > Date: Tuesday, December 9, 2008, 7:18 AM
> > Hi all,
> > can someone can tell me what is the "right" way
> > to sync a dataset with the
> > database.
> > I have try'd some diffrent ways with MySql and Npgsql
> > but in all ways Update
> > was not possible.
> > the filling of a dataset was no problem.
> > i use the ProviderFactory from Mono.Data
> >
> > Just do a adapter.Update has no effect
> >
> > with
> > CommandBuilder and GetUpdateCommand/ExecuteNonQuery
> >
> > Provider provider =
> > ProviderFactory.Providers["Mysql.Data"];
> > DbCommandBuilder builder =
> > (DbCommandBuilder)provider.CreateCommandBuilder(this.adapter);
> > DbCommand updateCommand = builder.GetUpdateCommand();
> > exception => "Cannot
> > cast from source to destination type" ???????
> >
> > the selectcommand of the adapter is valid an a adapte.fill
> > work right.
> >
> > any Help
> >
> > --
> > Top-Soft
> > Softwareentwicklung
> > Inhaber: Wolfgang Mauer
> > Reitesweg 9, 96103 Hallstadt
> > Tel.: +49 (0)951 / 2221520
> > Fax: +49 (0)951 / 2221521
> > _______________________________________________
> > Mono-list maillist  -  Mono-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list



-- 
Top-Soft
Softwareentwicklung
Inhaber: Wolfgang Mauer
Reitesweg 9, 96103 Hallstadt
Tel.: +49 (0)951 / 2221520
Fax: +49 (0)951 / 2221521


More information about the Mono-list mailing list