npgsql

How to use SQL parameters with NpgsqlDataAdapter?

别等时光非礼了梦想. 提交于 2019-12-20 06:46:53
问题 Is it possible to use parameters together with NpgsqlDataAdapter, as I can do with NpgsqlCommand: string sql = "SELECT * FROM tbl_student WHERE name = @val"; NpgsqlCommand command = new NpgsqlCommand(sql, conn); command.Parameters.AddWithValue("@val", name); I have this code, which displays the information about the students i a gridview: string sql = "SELECT * FROM tbl_student WHERE studentname = '" + name + "'"; DataSet ds = new DataSet(); DataTable dt = new DataTable(); NpgsqlDataAdapter

PostgreSQL data provider missing from wizard in Visual Studio 2015

陌路散爱 提交于 2019-12-20 04:23:22
问题 I've spent a day trying to migrate an Entity Framework 6 SQL Server CE to PostgreSQL. I've copied the database over fine, but I can't seem to get the data provider to work. Firstly I tried the older 2.2.7 version of the EF provider, which doesn't require .NET 4.5 (because our project can't use it), but that didn't work. I've been using NpgsqlConnection instead of SqlConnectionStringBuilder and changed the app.config to have a connection string with Host (I tried Server but it didn't like it)

postgresql does not appear in Data Source when generating .ADO.net Entity Data Model

試著忘記壹切 提交于 2019-12-18 16:32:15
问题 I succeeded in accessing an existing postgresql dbase by using npgsql directly. I used for this: PostgreSQL 9.0.10 (32 bit) Visual Studio 2015 Community (64 bit) NpgSql 2.2.5 (through Manage Nuget Packages) The dbase however has 25+ tables and 400+ columns and such my intention is to to use entity framework + .ADO.net Entity Data Model to avoid having to code access to all columns. I searched and tried everything on this site, npgsql site http://www.npgsql.org/doc/ddex.html, ... but I I did

Retrieve serial ID with Npgsql when inserting with ExecuteScalar

有些话、适合烂在心里 提交于 2019-12-18 04:48:14
问题 I'm trying to insert a row into a PostgreSQL table with a serial primary key and I need to retrieve this column after it was inserted. I got something like this: The table "pais" has 3 columns: id, pais, capital; id is a serial column and is its primary key. NpgsqlCommand query = new NpgsqlCommand("insert into pais(nombre, capital) values(@nombre, @capital)", conn); query.Parameters.Add(new NpgsqlParameter("nombre", NpgsqlDbType.Varchar)); query.Parameters.Add(new NpgsqlParameter("capital",

Is there a way to use ARRAYs in Entity Framework + PostgreSql

南笙酒味 提交于 2019-12-18 04:14:55
问题 Is it possible to use arrays in Entity Framework with PostgreSql? Suppose, for instance, we had the POCO class public class MyTable { [Key] [Column("gid")] public int Gid { get; set; } [Column("name")] public string Name { get; set; } [Column("email")] public string Email { get; set; } [Column("somedata")] public int[] SomeData { get; set; } } At this point Entity Framework simply does not create the column "somedata" and skips it. Is there a way to do this anyway? And by that I mean not

Using npgsql 12 and ef 6 together - have anyone succeeded with it?

喜欢而已 提交于 2019-12-18 03:41:39
问题 I'm trying to create a small POC for my boss about the hybrid of npgsql 12 and ef6, created a new project on visual studio created a sample database created the corresponding classes and the dbcontext yet, whenever I try and use ef to access the database I receive the folowing error: The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System

Using npgsql 12 and ef 6 together - have anyone succeeded with it?

夙愿已清 提交于 2019-12-18 03:41:36
问题 I'm trying to create a small POC for my boss about the hybrid of npgsql 12 and ef6, created a new project on visual studio created a sample database created the corresponding classes and the dbcontext yet, whenever I try and use ef to access the database I receive the folowing error: The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System

DBConcurrency Exception Occured While Updating Using Dataadapter

廉价感情. 提交于 2019-12-17 05:13:46
问题 I am trying to edit DataTable Filled by NpgsqlDataAdapter . After calling Fill() method, I have only one row in DataTable . Then I changed value of one column only and tried to update as below. Then I am getting this error: DBConcurrencyException occured My code is: NpgsqlDataAdapter getAllData = new NpgsqlDataAdapter("SELECT sn, code,product, unitprice, quantity, InvoiceNo, Date FROM stocktable WHERE Code='" + product + "' ORDER BY EDate ASC", DatabaseConnectionpg); DataTable ds1 = new

How to use NpgsqlCopyIn with NpgsqlCopySerializer?

坚强是说给别人听的谎言 提交于 2019-12-13 05:55:04
问题 If I understand correctly NpgsqlCopyIn with NpgsqlCopySerializer should work something like this: var conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["PostgreSqlDb"].ConnectionString); conn.Open(); var tran = conn.BeginTransaction(); var cmd = new NpgsqlCommand("COPY address (id, employee, value) FROM STDIN", conn); var npgsqlCopySerializer = new NpgsqlCopySerializer(conn); var npgsqlCopyIn = new NpgsqlCopyIn(cmd, conn, npgsqlCopySerializer.ToStream); try { npgsqlCopyIn

How to use NpgsqlParameter with ExecuteSqlCommand to avoid injection attacks? Getting NpgsqlException Error 42601: syntax error at or near \“(\”"

二次信任 提交于 2019-12-13 04:59:56
问题 I am using Entity Framework with PostgreSQL, which means I'm using Npgsql as the data provider. I would like to call context.Database.ExecuteSqlCommandAsync to make a query, and I'm trying to use parameters to avoid injection attacks. One example of a query I would like to make is alter table add column. Here is what my code looks like to set up the parameters and the sql query: NpgsqlParameter tableNameParam = new NpgsqlParameter("tableName", NpgsqlDbType.Text); tableNameParam.Value =