922 questions
0
votes
1
answer
1k
views
Insert foreign key into table with SQL query using C#
I have a database with 3 tables Identification, Identification_group and Group.
The Identification_group table has 2 foreign key columns, Identificaiton_id and Group_id.
In my form you can ...
1
vote
1
answer
150
views
Read SqlDataReader after Exception -- LIKE SSMS Result Pane
Is there a way to get the Reader object from SqlCommand.ExecuteReader without failing on SqlException?
In SSMS, for this command:
RAISERROR (15600, 12, 5, 'example');
SELECT * FROM TableName
I got ...
0
votes
1
answer
326
views
ADO.NET SqlCommand not returning correct value for SCOPE_IDENTITY()
I have a simple table :
CREATE TABLE [MyTable]
(
[ID] [INT] IDENTITY(1,1) NOT NULL,
[NAME] [NVARCHAR](100) NOT NULL,
[DATA] [NVARCHAR](max) NOT NULL,
CONSTRAINT [PK_MyTable]
...
3
votes
1
answer
10k
views
Adding parameters to SQLCommand and adding value later
I've seen the different discussions of using Parameters.Add vs Parameters.AddWithValue (one is explicit, the other is not), but that isn't my issue.
I'm defining a command, which will be used to do ...
0
votes
4
answers
271
views
Adding a class type to database
public class Person
{
public int PersonId { get; set; }
public string SurName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
...
0
votes
1
answer
87
views
SqlConnection ExecuteAsync hangs on Linux but not on Windows
ASP.Net Core
I have the code than calls
var resp = await conn.ExecuteAsync("procedureName", sqlParams, commandType: CommandType.StoredProcedure).ConfigureAwait(false)
When I start my application on ...
0
votes
2
answers
2k
views
SqlParameter not supplied when using Parameters.AddWithValue
This is how I set up my command. It stops with the first parameter, UpdateType. This code is being updated from VB.NET 2008 version.
Dim db As New DB()
Dim cmd As SqlCommand = New SqlCommand()
'Put ...
-1
votes
2
answers
75
views
I need help on IF EXIST ELSE
I need help on this line
string query = @"IF EXISTS(Select * From u_Data Where TAG = '" + txtTag.Text + "') begin Update u_data set Name = '" + txtNama.Text +
"', NIK = '" + txtNIK....
-2
votes
1
answer
491
views
Compare two tables for a matching value from the respective columns and identify records missing
I have two tables and data like below:
I want to compare two table's columns "Type and MatchType" and identify the Ids of first table where Type is missing in MatchType. "Type" and "MatchType" are ...
-1
votes
1
answer
1k
views
How to specify ReadOnly query in C# using SqlCommand()
I'm using C# with .NET SqlDataReader(), SqlConnection(), SqlCommand() and .ExecuteReader() classes.
In vbScript, I can open RecordSets like this:
rs.open cSQL, cn, adOpenForwardonly, adLockReadonly
...
0
votes
0
answers
169
views
Pass two value with two parameters in c# into sqlcommand and read value to disable button?
I am trying to get this method to read values from the database as well as to get values from an asp.net webform.
I have tried the code below but never worked
public void CheckLikedEvents()
...
-2
votes
2
answers
96
views
Insert into data to database Error Parameters [closed]
I want to insert my DataGridView datas to my database i used parametrs
these are my database fileds
CREATE TABLE [dbo].[Tbl_Order] (
[Name] VARCHAR (50) NULL,
[Price] INT ...
-1
votes
2
answers
86
views
How to Refresh the Datagridview using c#.net
i am creating a simple crud in c#.net.after add the record record will show on the datagridview itself. but i couldn't do it. code which tried so far i attched below.
code
sql = "insert into student(...
0
votes
1
answer
2k
views
C# Check if the data already exists
I have a product record table in the database, it will save the following: ID, product code, product name, size, and price. A product can have the same size and price right? In my code, I am trying to ...
0
votes
1
answer
155
views
How to insert into database SQL transaction?
I've got a Log method:
public void Log(string log)
{
command = new SqlCommand() { Connection = connection };
command.CommandText = "INSERT INTO Logs (Date, Login, Transact) " +
$"VALUES ('...
-2
votes
1
answer
2k
views
MySQL to find the number of employee(s) for each month
This is the table named employee.
This is the question and sample output
SELECT MONTH(EMP_HIREDDATE) AS “Hire Month”, COUNT(EMP_NUM) AS “No Of Employee”
FROM EMPLOYEE
GROUP BY EMP_NUM;
The above ...
0
votes
2
answers
107
views
Why does my count command in mysql return wrong value -1?
I'm using gcloud mysql and inserting values and stuff using c#.
Im trying to get amount of records in table Categories_tbl. My code is:
but after executing x is equal to -1 which wrong. what could it ...
1
vote
1
answer
372
views
Passing Second Parameter to Stored Procedure in C#
In the following code, I'm trying to retrieve the ID of the manager which then has to be passed as the second parameter to the SQL Stored procedure as shown in the code below:
Currently the code uses ...
0
votes
0
answers
373
views
Error converting from varchar value to int value
the problem that I have is 'Conversion failed when converting the varchar value '@param4' to data type int.'
I'm new to databases and don't know how to nest SQL injections(I hope i'm using the term ...
0
votes
2
answers
936
views
How to programmatically check if a SQL database/server supports compression in C#?
Building a tool to backup a database that I'm testing locally first. I'm trying to check if compression is supported and change my SQL query based on the value returned. Running it against an actual ...
-1
votes
2
answers
73
views
Object is null using SqlCommand stored procedure to Object
I am trying to execute a SQL stored procedure and collect the results in a List<T>. I do not get errors, but the list is always null. The stored procedure produces over 100 records so I know ...
2
votes
0
answers
763
views
How to read complete result of FOR XML SQL Server Query?
I want to save the complete result of a FOR XML SQL Query to a file.
My SQL Query looks something like this:
SELECT * FROM Customer FOR XML RAW
in my code, I now want to execute this query against ...
0
votes
0
answers
84
views
C# SqlCommand - Prevent typecasting if a string is specified as a parameter
I am using a SQL Server database in my C# project. Currently I give my SQL query parameters via the AddWithValue function without the explicit specification of inverted commas. Can I be sure that ...
0
votes
1
answer
575
views
A better way to populate a class object from a database query?
Currently I am using SqlCommands to run stored procedures, I will ExecuteReader and run a while .read, assigning each field to an object then adding that object to a list. This has worked fine so far ...
0
votes
1
answer
220
views
Gridview DataSource doesn't update
With a button press I'm trying to update the GridView on my ASP.net site with Database from SQL server with other table but it doesnt change, there is no "catch".
The GridView doesn't appear.
{
...
2
votes
0
answers
88
views
Change parameter indicator in SqlCommand from '@' to ':'
I'm working on library which allows me to create connections, commands, readers etc for 3 db types: oracle, postgresql and sql server. I need to pass parameters into query but it seems like postgres ...
0
votes
1
answer
328
views
how to write query in ado.net consist of data dictionary
i want to write query which is written using linq and data dictionary i want to convert that query in ado.net form
var insData = new Dictionary<string, string>();
insData =...
0
votes
1
answer
410
views
Receiving json string database MS SQL database, formatting problem
I run a C# app, which gets json from MS SQL 2016 using a stored procedure.
string t = da.ExecuteScalar().ToString();
I get strangely formatted json:
"{\"Komponent\":\"00066X96A\",\"Opis\":\"Part2 II ...
0
votes
1
answer
348
views
Stored procedure OUTPUT string result is only one char instead of full string
I have some problem with this code, the return variable I want is "Sơn" instead of 'S'
My code:
SentoDB.RunProcedure("usp_GetNameWithIdCategory");
SqlParameter CategoryID = new SqlParameter("...
2
votes
3
answers
147
views
Problem with query string and extract values
I can't extract the values through a query and insert them into textboxes
Where am I going wrong?
Request.QueryString.Get("ID_Persona");
string query = "SELECT ID,Nome,Cognome,Email,CodiceFiscale ...
0
votes
1
answer
463
views
How to get to get the value of @@identity or SELECT SCOPE_IDENTITY() from stored procedure in C# code?
I use SQL Server 2012. In this stored procedure, I want to get the value of @@identity or SELECT SCOPE_IDENTITY(). intMyIdentity is the identity column.
CREATE PROCEDURE [spMyInsert]
(@vchVar AS ...
0
votes
1
answer
46
views
Issue with Open DataReader which must be closed first
I am getting the following error in my code:
"There is already an open DataReader associated with this Command
which must be closed first."
I have two SqlDataReaders and I made sure that I closed ...
0
votes
1
answer
338
views
SqlDataReader - Populate child list with all the items that match
I am trying to populate parent objects with child object that match but cannot figure out how to only display the ones that match.
I manage to get the child objects and add them to the list but it ...
0
votes
1
answer
533
views
OleDB Select command not working with multiple OR statements (C#)
I am using the below select statement to pick up data from excel and drop it into a datatable. There is a bad row in there that I do not want to pick up so thats this part [Plan] <> 'PLAN_BO' ...
0
votes
0
answers
392
views
SqlDependency OnChangeEventHandler not firing when query changed inSqlCommand
I have written code using SqlDependency. In using select statement with list of columns, OnChangeEventHandler event is fired but when I change select statement to get count of rows, ...
0
votes
1
answer
1k
views
Visual Studio Database Project - Use SqlCmd Variable as Schema Name
I am trying to create stored procedures with different schemas using SQL Command Variables, however I cannot build the project due to the error:
SQL71501: Procedure: [$(SchemaName)].[pr_MySproc] has ...
0
votes
0
answers
82
views
C# - Dealing with many-to-many without an ORM
I have two database tables that are many-to-many
tblBook
idBook
Title
Writer
ect...
tblBookGenre
id
idBook
idGenre
tblGenre
idGenre
NameGenre
And
tblBook
idBook
Title
Writer
ect...
tblBookTag
...
4
votes
1
answer
2k
views
C# ExecuteScalar() null COUNT vs SELECT
I noticed some odd behavior and hoped one of the experts could explain the difference. My UI requires an image is unique before presenting it to the user for their task. I store checksums in the ...
0
votes
1
answer
199
views
How to select data from local database when it is not present in remote database
Is it possible to select data rows from local database when those rows are not present in remote database?
I wrote a code, but it doesn't work: conlocal is the local database connection, and conremote ...
-3
votes
2
answers
527
views
How can I set the time out, in the command and the connection?
this is my code in the dataset.cs.
what do I have to add for set the timeout in the connection and the command?
namespace M_Report
{
partial class A_DBDataSet
{
partial class ...
0
votes
1
answer
3k
views
SQL Server query Where string has ':' colon in it returns not found
I am trying to query the table to look for record like this:
string owner = "sometextlikethis";
string pictureName = "pexels-photo.jpg_15-Apr-19 07:59:37"; //problem
PictureLibrary _pictureObj = new ...
3
votes
0
answers
103
views
SqlCommand Read() hanging randomly when returning results on Windows Server 2016 / SQL Server 2016
I have a custom application that builds a Lucene Index on our various SQL Server VMs hosted in Azure (it runs locally on the machine. I know this isn't ideal, but reasons). This program has run ...
0
votes
1
answer
102
views
How to get stored procedure out type value in mvc c# List<T> type public function [duplicate]
I am trying to get total count of records in "@TotalRecordsCount" which will be returned after applying all my search parameters. but it is always giving me null value. i tried other matching options ...
0
votes
1
answer
1k
views
Can we run index rebuild or reorganize commands from C# winform?
I want to know is it possible to run MS SQL Server index rebuild or reorganize operations from c# winform?
I have a script using rebuild and reorganize. Now I want to run the whole script on the ...
-1
votes
2
answers
103
views
How to Divide Sql Column
I want to share the SQL table column. The first column will contain data upto 1-10, 11-20 in the second column and 21-30 in the 3rd column in the form of data.
-1
votes
1
answer
45
views
How do i resolve this procedure or function 'SelectFollow' expects parameter '@userid', which was not supplied.'?
I am trying to get the current userid from the parameter and to check if it exists in a Database Table using stored procedure
public PartialViewResult AllStates(string state, string userid)
{
...
1
vote
2
answers
380
views
sqlcommand c# method with sql paramather
I have this method, which I have in the base class that helps me to select anything from the children classes and also to reduce code repetition. The problem is when I call it I get an error which is ...
3
votes
2
answers
1k
views
Rolling sum till a certain value is reached, plus calculated duration
I have a requirement where I need to know when the sum(value) reaches certain point and calculate duration. Below is the sample table.
create table sample (dt timestamp, value real);
insert into ...
1
vote
1
answer
57
views
C# - SQL Query Rounding Problem while adding DataGridView
I have an SQL query and it has comma value. When I adding it to DataGridView I want to this format (#, ##). I tried Math.Round() function but it doesn't work.
Below is the query I have tried:
(...
0
votes
2
answers
2k
views
SQL - Mathematical (Min - Max Normalisation)
I want to normalization operation in my code. I have a SQL - Server table, it has 3 columns; first column has single words, second column has single words, third column has integer values. I ...