Postgres - problems with NpgsqlDataAdapter insert

From: "Evan Sherwood" <esherwood(at)hotmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Postgres - problems with NpgsqlDataAdapter insert
Date: 2006-03-16 07:39:18
Message-ID: BAY104-F30FB41BFF3DF5653E21E59B5E70@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

<html><div style='background-color:'><DIV class=RTE>Hi</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>I am having problems with the NpgsqlDataAdapter. I created an insert command and when I call the update method, I get an error:&nbsp; ERROR: 42601: syntax error at or near":"</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>If I remove some of the columns from the insert statement, it works.&nbsp;It seems like&nbsp;there is a limit to the length of the command text.</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>I am using C# 2003 (.NET Framework 1.1) on Windowx XP.</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>I create the data adapter using the following code:</DIV><FONT size=2>
<P class=RTE></FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> poSelect = "SELECT po_number, supplier, originated_by, deliver_to, " +</FONT></P>
<P class=RTE><FONT size=2>"po_status_code, shipping_company, ship_point, service_order, " +</P>
<P class=RTE>"fob, freight, internal_comments, external_comments, currency, " +</P>
<P class=RTE>"hide_cost_on_printout " +</P>
<P class=RTE>"FROM purchase_order";</P>
<P class=RTE>m_daPO = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlDataAdapter(poSelect, m_posDBConn);</P>
<P class=RTE></FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> poInsert = "INSERT INTO purchase_order (po_number, supplier, currency, " +</P>
<P class=RTE>"originated_by, deliver_to, po_status_code, shipping_company, fob, freight, " +</P>
<P class=RTE>"internal_comments, external_comments, service_order, hide_cost_on_printout) " +</P>
<P class=RTE>"VALUES (:po_number, :supplier, :currency, " +</P>
<P class=RTE>":originated_by, :deliver_to, :po_status_code, :shipping_company, :fob, :freight, " +</P>
<P class=RTE>":internal_comments, :external_comments, service_order, :hide_cost_on_printout)";</P>
<P class=RTE>NpgsqlCommand poInsertCmd = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlCommand(poInsert, m_posDBConn);</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("po_number", DbType.Int16));</P>
<P class=RTE>poInsertCmd.Parameters["po_number"].SourceColumn = "po_number";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("supplier", DbType.Int16));</P>
<P class=RTE>poInsertCmd.Parameters["supplier"].SourceColumn = "supplier";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("currency", DbType.String));</P>
<P class=RTE>poInsertCmd.Parameters["currency"].SourceColumn = "currency";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("originated_by", DbType.Int16));</P>
<P class=RTE>poInsertCmd.Parameters["originated_by"].SourceColumn = "originated_by";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("deliver_to", DbType.Int16));</P>
<P class=RTE>poInsertCmd.Parameters["deliver_to"].SourceColumn = "deliver_to";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("po_status_code", DbType.Int16));</P>
<P class=RTE>poInsertCmd.Parameters["po_status_code"].SourceColumn = "po_status_code";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("shipping_company", DbType.Int16));</P>
<P class=RTE>poInsertCmd.Parameters["shipping_company"].SourceColumn = "shipping_company";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("freight", DbType.String));</P>
<P class=RTE>poInsertCmd.Parameters["freight"].SourceColumn = "freight";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("fob", DbType.String));</P>
<P class=RTE>poInsertCmd.Parameters["fob"].SourceColumn = "fob";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("internal_comments", DbType.String));</P>
<P class=RTE>poInsertCmd.Parameters["internal_comments"].SourceColumn = "internal_comments";</P>
<P class=RTE>poInsertCmd.Parameters.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> NpgsqlParameter("external_comments", DbType.String));</P>
<P class=RTE>poInsertCmd.Parameters["external_comments"].SourceColumn = "external_comments";</P>
<P class=RTE>m_daPO.InsertCommand = poInsertCmd;</P>
<P class=RTE>&nbsp;</P>
<P class=RTE>After that I load the data using the Fill method of the data adapter. Then a new row is inserted into the "po" DataTable. I check the DataSet and the row has been added.</P>
<P class=RTE>Then I save the data. Here is first part of the code for the update:</P><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>try</P></FONT><FONT size=2>
<P>{</P>
<P>m_posDBConn.Open();</P>
<P>poUpdate = m_posDBConn.BeginTransaction();</P>
<P>m_daPO.InsertCommand.Transaction = poUpdate;</P>
<P></FONT><FONT color=#0000ff size=2>try</P></FONT><FONT size=2>
<P>{</P>
<P>m_daPO.Update(m_dsPO, "po");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // this causes error</P>
<P>poUpdate.Commit();</P></FONT>
<P class=RTE>...</P>
<P class=RTE>&nbsp;</P>
<P class=RTE>I would appreciate help with this as soon as possible because it is impeding development.</P>
<P class=RTE>Thanks.</P>
<P class=RTE>Evan</P>
<P class=RTE>&nbsp;</P></FONT></div></html>

Attachment Content-Type Size
unknown_filename text/html 5.5 KB

Browse pgsql-interfaces by date

  From Date Subject
Next Message Zlati 2006-03-16 12:33:59 linking C with libpq
Previous Message Christopher Kings-Lynne 2006-03-14 02:53:19 Re: [PATCHES] Proposed patch for error locations