Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

42804: column is of type timestamp without time zone but expression is of type text #630

Closed
sarath22 opened this issue Sep 6, 2018 · 1 comment

Comments

@sarath22
Copy link

sarath22 commented Sep 6, 2018

I'm trying to insert c#'s System.DataTime value into table and whose column type is timestamp time without zone. Please find my table structure and C# code below:

Table:

CREATE TABLE public."TestingDetails"
(
"TestID" integer NOT NULL,
"TestName" text,
"TesterName" text,
"TotalCount" integer,
"SuccessCount" integer,
"FailureCount" integer,
"EndDate" timestamp without time zone,
"StartDate" timestamp without time zone,
CONSTRAINT "TestingDetails_pkey" PRIMARY KEY ("TestID"),
CONSTRAINT "TestingDetails_TestID_key" UNIQUE ("TestID")
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."TestingDetails"
OWNER TO postgres;

C# code:

string connstring = "Server=localhost;Port=5432;Database=test;User Id=postgres;Password=sync1694";
// Making connection with Npgsql provider
NpgsqlConnection conn = new NpgsqlConnection(connstring);
conn.Open();
if (conn.State == System.Data.ConnectionState.Open)
{
string sql = "SELECT * FROM public."TestingDetails" ";
// data adapter making request from our connection
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
ds.Reset();
// filling DataSet with result from NpgsqlDataAdapter
da.Fill(ds);
// since it C# DataSet can handle multiple tables, we will select first
int _TestID=0;
string _TestName = "test";
string _TesterName = "demo";
DateTime _EndDate = DateTime.Now;
DateTime _StartDate = DateTime.Now;
int _TotalCount = 10;
int _SuccessCount = 5;
int _FailureCount = 5;
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
_TestID = dt.Rows.Count + 1;
}
//new NpgsqlDateTime()
//dt.
//NpgsqlCommand command = new NpgsqlCommand("insert into public."TestingDetails" (TestID, TestName, TesterName, TotalCount, SuccessCount, FailureCount) values(" + _TestID + ",'" + _TestName + "','" + _TesterName + "'," +_TotalCount + "," + _SuccessCount + "," + _FailureCount + ")", conn);
NpgsqlCommand command = new NpgsqlCommand("insert into public."TestingDetails" values(:_TestID , :_TestName , :_TesterName , :_TotalCount , :_SuccessCount, :_FailureCount, :_StartDate)", conn);
command.Parameters.Add(new NpgsqlParameter("_TestID", _TestID));
command.Parameters.Add(new NpgsqlParameter("_TestName", _TestName));
command.Parameters.Add(new NpgsqlParameter("_TesterName", _TesterName));
command.Parameters.Add(new NpgsqlParameter("_StartDate", _StartDate));
command.Parameters.Add(new NpgsqlParameter("_TotalCount", _TotalCount));
command.Parameters.Add(new NpgsqlParameter("_SuccessCount", _SuccessCount));
command.Parameters.Add(new NpgsqlParameter("_FailureCount", _FailureCount));
command.Parameters.Add(new NpgsqlParameter("_EndDate", _EndDate));
command.ExecuteNonQuery();
}
@austindrenski
Copy link
Contributor

@sarath22 As mentioned previously, this issue needs to be opened in the repository for the ADO.NET driver: https://github.com/npgsql/npgsql. This repository is strictly concerned with the EF Core provider for Npgsql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants