473,387 Members | 1,569 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,387 software developers and data experts.

PostgreSQL object datatype

Hi,

I'm having a problem, I'm using PostgreSQL V8.3.3-1, Npgsql and Visual studio 2008 c#.

I'm passed a dictionary of key, value (key been a string, value been an object). The code works fine with key and value both been strings but postgresql doesn't seem to like it when the value is an object. How can I correct my code to work when passed an object? I realise that rowsaffected is currently only storing the first value, that's fine. I just want to be able to run a query using an object datatype for now.

current error is: "InvalidCastException is unhandled by user code"

sql is a query
Expand|Select|Wrap|Line Numbers
  1. "SELECT username FROM users WHERE age = :Value1"
Expand|Select|Wrap|Line Numbers
  1.         public static string GetSql(string sql, Dictionary<string, object> d)
  2.         {
  3.             string connection = System.Configuration.ConfigurationManager.ConnectionStrings["POSTGRESQL_LOCAL"].ConnectionString;
  4.  
  5.             using (NpgsqlConnection conn = new NpgsqlConnection(connection))
  6.             {
  7.                 conn.Open();
  8.                 using (NpgsqlCommand command = new NpgsqlCommand(sql, conn))
  9.                 {
  10.                     int i = 0;
  11.  
  12.                     foreach (KeyValuePair<string, object> kvp in d)
  13.                     {
  14.                         command.Parameters.Add(new NpgsqlParameter(kvp.Key, DbType.Object));
  15.                         command.Parameters[i].Value = kvp.Value;
  16.                         i++;
  17.                     }
  18.                     string rowsaffected = "error: No data";
  19.                     using (NpgsqlDataReader dr = command.ExecuteReader())
  20.                     {
  21.                         while (dr.Read())
  22.                         {
  23.                             rowsaffected = dr[0].ToString();
  24.                         }
  25.                     }
  26.  
  27.                     conn.Close();
  28.                     return rowsaffected;
  29.  
  30.                 }
  31.  
  32.             }
  33.  
  34.         }
I hope I placed this on the correct forum. Most of the code is c# but I feel the problem lies with Postgresql...

Thanks
Jun 30 '08 #1
0 2621

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

Similar topics

3
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if...
4
by: Morten Goodwin Olsen | last post by:
Python, PostgreSQL and bytea Hi I am having a bit of trouble inserting images into a postgres database using python. The images should be stored in a bytea field. I have tried both with an odbc...
2
by: Seb | last post by:
I am trying to initialize a const static object data member in a header file? The following code errs. class Object { public: virtual const char* ToString() { return "Object"; } virtual...
11
by: Errol Neal | last post by:
Hi all, Not sure if this is a question for a php list or this one, but I'll give it a shot and if I am wrong, please do not crucify me. :-) There is a php based sourceforge project called...
3
by: Robert Abi Saab | last post by:
Hi everyone. I just finished a course on PostgreSQL and I found out that PostgreSQL doesn't provide any object relational features (as claimed in the official documentation), except table...
1
by: NTPT | last post by:
I need to do some "IP address based guessing" what should happen inside my application.Ie if given ip adress is from network 'foo' do something, if given IP adrss is from network 'bar', do...
5
by: Miguel Guzman Miranda | last post by:
Hi there, First of all, I suppose my problem should be at least farly common, but haven't had luck trying to find what I need by searching on the docs, google, etc. So please if this issue has...
5
by: Jerome Lyles | last post by:
I took the white space between characters out of my script 'create.txt4' and ran it on database 'test'. There were errors: 26 27 -- Create Orders Table 28 29 CREATE TABLE Orders 30 ( 31 ...
0
by: Kless | last post by:
It would be very interesting if the python community could to access since SQLAlchemy to more features of the PostgreSQL 8.3 RDBMS powerful, as are any new data types as: enumerated (ENUM) , XML...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.