executescalar

Cannot implicitly convert type 'int?' to 'int'.

非 Y 不嫁゛ 提交于 2020-05-23 05:33:24
问题 I'm getting the error "Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?)" on my OrdersPerHour at the return line. I'm not sure why because my C# skills are not that advanced. Any help would be appreciated. static int OrdersPerHour(string User) { int? OrdersPerHour; OleDbConnection conn = new OleDbConnection(strAccessConn); DateTime curTime = DateTime.Now; try { string query = "SELECT COUNT(ControlNumber) FROM Log WHERE DateChanged > #" +

ExecuteScalar always returns 0

无人久伴 提交于 2020-01-17 17:45:30
问题 I'm not sure why this is happening. I've seen the same issue online with little help out there to correct it. When i run my query inside Access i get different values ranging from 0 - 10 but for some reason, it won't return that same value inside my code. static int OrdersPerHour(string User) { int? OrdersPerHour = 0; OleDbConnection conn = new OleDbConnection(strAccessConn); DateTime curTime = DateTime.Now; try { string query = "SELECT COUNT(ControlNumber) FROM Log WHERE DateChanged > #" +

ExecuteScalar always returns 0

你。 提交于 2020-01-17 17:45:02
问题 I'm not sure why this is happening. I've seen the same issue online with little help out there to correct it. When i run my query inside Access i get different values ranging from 0 - 10 but for some reason, it won't return that same value inside my code. static int OrdersPerHour(string User) { int? OrdersPerHour = 0; OleDbConnection conn = new OleDbConnection(strAccessConn); DateTime curTime = DateTime.Now; try { string query = "SELECT COUNT(ControlNumber) FROM Log WHERE DateChanged > #" +

What is a “Scalar” Query?

最后都变了- 提交于 2019-12-21 07:36:11
问题 I am using LLBLGEN where there is a method to execute a query as a scalar query . Googling gives me a definition for scalar sub-query , are they the same ? 回答1: A scalar query is a query that returns one row consisting of one column. 回答2: For what it's worth: Scalar subqueries or scalar queries are queries that return exactly one column and one or zero records. Source 回答3: A scalar method is used for aggregate functions such as max, min, sum, avg and so on. Whenever you want to return a

Display SQL query result in a label in asp.net

☆樱花仙子☆ 提交于 2019-12-19 09:39:09
问题 I'm trying to display the SQL query result in a label but it's not showing. This is my code: string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' "; SqlCommand showresult = new SqlCommand(result, conn); conn.Open(); showresult.ExecuteNonQuery(); string actresult = ((string)showresult.ExecuteScalar()); ResultLabel.Text = actresult; conn.Close(); Need help please. Thanks! 回答1: Try this one. string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' ";

Display SQL query result in a label in asp.net

不问归期 提交于 2019-12-19 09:39:07
问题 I'm trying to display the SQL query result in a label but it's not showing. This is my code: string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' "; SqlCommand showresult = new SqlCommand(result, conn); conn.Open(); showresult.ExecuteNonQuery(); string actresult = ((string)showresult.ExecuteScalar()); ResultLabel.Text = actresult; conn.Close(); Need help please. Thanks! 回答1: Try this one. string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' ";

oracle ExecuteScalar in parallel programming sometimes returns null

[亡魂溺海] 提交于 2019-12-13 04:23:13
问题 I used parallel programming to perform two parallel oracle database queries. Sometimes the "res" object returns as null. Any idea why? Note that this is a count query of the same table and nothing is modifying this table so the database table and the query are not changing. string query = "select count(*) from SALES_ADVENTUREWORKS2012.SALESORDERDETAIL where PRODUCTID=709"; tasks[0] = Task.Factory.StartNew(() => db.ExecScalarQuery(query)); tasks[1] = Task.Factory.StartNew(() => db

Display .sql output from OracleConnection C#

℡╲_俬逩灬. 提交于 2019-12-13 00:56:09
问题 There's simple .sql file like this:- helloworld.sql DECLARE message varchar2(20):= 'Hello, World!'; BEGIN dbms_output.put_line(message); END; I want to call the file in C# console app, catch and display the output in console. Supposedly, it should just output Hello, world! in the console. This is what I've tried so far. Program.cs string sqlConnectionString = @"User Id=user;Password=password123;Data Source=xxxx.xxx.COM"; string script = File.ReadAllText(@"\\test\\helloworld.sql"); try { using

ExecuteScalar not returning right values C#

北城以北 提交于 2019-12-12 04:36:05
问题 Let me start by posting my code first: ExecuteScalar method: public T ExecuteScalar<T>(string sql, CommandType commandType, List<NpgsqlParameter> parameters) { using (NpgsqlConnection conn = Konekcija_na_server.Spajanje("spoji")) { return Execute<T>(sql, commandType, c => { var returnValue = c.ExecuteScalar(); return (returnValue != null && returnValue != DBNull.Value && returnValue is T) ? (T)returnValue : default(T); }, parameters); } } Execute method: T Execute<T>(string sql, CommandType

How can I get the actual datetime values from a SQLite table?

旧巷老猫 提交于 2019-12-11 19:29:48
问题 I am querying a SQLite table which has a DateTime member: public class PhotraxBaseData { [SQLite.PrimaryKey] [SQLite.AutoIncrement] public int Id { get; set; } . . . public DateTime dateTimeTaken { get; set; } . . . The records in the table contain dateTimeTaken values ranging from 2008 to 2014. None of the records contain a null or empty dateTimeTaken value. When queried via LINQPad, I get "2008-04-25 10:38:56" for this query: SELECT MIN(dateTimeTaken) FROM PhotraxBaseData ....and "2014-04