Cannot insert explicit value for identity column in table 'OS_Mailinglist1' when IDENTITY_INSERT is set to OFF - c#-2.0

Can anyone help me why I am getting this error? Thanks in advance..
Cannot insert explicit value for identity column in table
'OS_Mailinglist1' when IDENTITY_INSERT is set to OFF. Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details:
System.Data.SqlClient.SqlException: Cannot insert explicit value for
identity column in table 'OS_Mailinglist1' when IDENTITY_INSERT is set
to OFF.
Source Error:
Line 312: cmd.ExecuteNonQuery();
Line 313: ClientScript.RegisterStartupScript(this.GetType(), "alert",
"alert('Successsfully Registered your Email ID and Area of
interest.');", true);
Code behind page that shows error:
else
{
Util.SetConnection();
Util.sql_con.Open();
cmd = new SqlCommand("insert into offsale.OS_Mailinglist1(UserName,Area_Of_Interest,Mail_Pwd)values('" + txtEmail.Text.ToString() + "' ,'" + arrvalues + "','" + ViewState["pwd"].ToString () + "')", Util.sql_con);
// cmd = new SqlCommand("insert into offsale.OS_Mailinglist1(UserName,Area_of_interest,Mail_Pwd)values('" + txtEmail.Text.ToString() + "' ,'" + arrvalues + "','" + passwrd.Text.ToString () + "')", Util.sql_con);
cmd.ExecuteNonQuery();
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Successsfully Registered your Email ID and Area of interest.');", true);
Util.sql_con.Close();

you are trying to insert a value into an identity column. to explicitly allow this you have to to turn the global IDENTITY_INSERT session value on.

Related

Exporting Google Ads Calls to Sheets From Campaigns

function main() {
var spreadsheet = SpreadsheetApp.create("Report output");
var report = AdsApp.report("SELECT metrics.phone_calls, " +
"FROM campaign " +
"WHERE segments.date BETWEEN '2022-01-01' AND '2022-07-03'");
report.exportToSheet(spreadsheet.getActiveSheet());
Logger.log("Report available at " + spreadsheet.getUrl());}
Returning this error: Exception: Call to GoogleAdsService.Search failed: Error in SELECT clause: invalid field name 'FROM'.
How can I make this work?

Basic stored procedure - why isn't this working?

New to SPs in Snowflake. I cannot work out why this doesn't work??
Error message is: JavaScript compilation error: Uncaught SyntaxError: Invalid or unexpected token in LOAD_CUSTOMERS at 'var sql = '' position 10
I'd really appreciate someone pointing out what is wrong here to get me going!
'''
CREATE OR REPLACE SCHEMA stage;
CREATE OR REPLACE TABLE stage.load_customers
(FIRST_NAME VARCHAR);
CREATE OR REPLACE PROCEDURE stage.load_customers(VAR_SCHEMA VARCHAR, VAR_TABLE VARCHAR)
returns string
language javascript
as
$$
var sql = '
INSERT OVERWRITE INTO AM_TEST.';
sql += VAR_SCHEMA;
sql += '.';
sql += VAR_TABLE;
sql += '
SELECT C_FIRST_NAME FROM SNOWFLAKE_SAMPLE_DATA.TPCDS_SF100TCL.CUSTOMER LIMIT 100;
try {
snowflake.execute (
{sqlText: sql}
);
return "Succeeded."; //Return a success
}
catch (err) {
return "Failed: " + err; //Return error
}
$$;
call stage.load_customers('stage', 'load_customers');
Can you try your return("success") statement as return(sql) and execute the sql statement separately to validate the syntax and access issue.
Also the quote started before select statement is missing it end?
Using backtick (`) will make your sp creation easier and more readable.
The following one is working as expected :
CREATE DATABASE AM_TEST;
CREATE OR REPLACE SCHEMA stage;
CREATE OR REPLACE TABLE stage.load_customers
(FIRST_NAME VARCHAR);
CREATE OR REPLACE PROCEDURE stage.load_customers(VAR_SCHEMA VARCHAR, VAR_TABLE VARCHAR)
returns string
language javascript
as
$$
var sql = `INSERT OVERWRITE INTO AM_TEST.` + VAR_SCHEMA + `.` + VAR_TABLE
+ ` SELECT C_FIRST_NAME FROM SNOWFLAKE_SAMPLE_DATA.TPCDS_SF100TCL.CUSTOMER LIMIT 100;`;
try {
snowflake.execute (
{sqlText: sql}
);
return "Succeeded."; //Return a success
}
catch (err) {
return "Failed: " + err; //Return error
}
$$;
call stage.load_customers('stage', 'load_customers');

WIQL query to get all item under a workitem

I am looking for a query where i can return all work items and their relation from a area path.
for example : project 1
i need all Featured all Userstories mapped to it all workitem and Bug mapped to userstories,
in short if i took a bug from the object i need somthing like parent id where i can match with the userstory.
string query1 = " SELECT * FROM WorkItemLinks " +
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
which throwing an error like below
An exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll but was not handled in user code
Additional information: TF51005: The query references a field that does not exist. The error is caused by «[System.IterationPath]».
when i checked the dll's are refereed correctly and when i re wrote the query like this the query is working fine
string query = " SELECT * FROM WorkItems"+
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
//" AND ([System.State] = 'Active' OR [System.State] = 'Assessed' ) "+
//" AND ( [Microsoft.VSTS.Scheduling.StartDate] <= '09/13/2017' AND [Microsoft.VSTS.Scheduling.FinishDate] >= '09/13/2017' )"+
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
but this query result does not give the relation ship that if a work item mapped as a child to other i need parent id in the work item object. how to get that. Thanks in advance.
You can try below query:
Install Nuget Package Microsoft.TeamFoundationServer.ExtendedClient for the project.
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
namespace _0925_WIQL
{
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
new Uri("http://server:8080/tfs/CollectionLC"));
WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));
string query1= " SELECT * FROM WorkItemLinks " +
" WHERE ( Source.[System.IterationPath] Under 'TeamProject\\Iteration 1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
Query query = new Query(workItemStore, query1);
WorkItemLinkInfo[] witLinkInfos = query.RunLinkQuery();
foreach (WorkItemLinkInfo witinfo in witLinkInfos)
{
.......
}
Besides, you can also use Wiql Editor. If you want to get all the parent workitems (IDs) from a specific child work item (ID), you can use below WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State]
FROM workitemLinks
WHERE ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND ([Target].[System.Id] = 25)
ORDER BY [System.Id]
MODE (Recursive, ReturnMatchingChildren)

FireDAC Query connect to DBGrid

I have FDQuery and DataSource and DBGrid. Now I write this code in Button
FDQuery2->Active = false;
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = " + MaskEdit1->Text +
" ORDER BY C.check_id ");
FDQuery2->Active = true;
and i connect FDQuery to DataSource and tDataSource to DBGrid, but when I click the Button it doesn't show rows. and i am sure that SQL code is work, because when i write inside the SQL String the rows have been shown.
any ideas.
You're missing the ' around your value when concatenating the text. Change your WHERE clause:
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = '" + MaskEdit1->Text + "'" +
" ORDER BY C.check_id ");
You really should learn to use parameterized queries instead, though. It allows the database driver to handle things like properly quoting text or formatting dates for you, and it also (importantly) prevents SQL injection.
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = :today" +
" ORDER BY C.check_id ");
FDQuery2->ParamByName("today")->AsString = MaskEdit1.Text;
FDQuery2->Active = true;

Cannot set htmlAttribute parameter

I'm adding in the object htmlAttributes parameter and getting an error :
"Error 41 Invalid anonymous type
member declarator. Anonymous type
members must be declared with a member
assignment, simple name or member
access"
Response.Write(Html.CheckBox("chkStatus", item.Value) + " " + item.Text + "<br />");
Response.Write(Html.CheckBox("chkStatus", item.Value,new {checked=true}) + " " + item.Text + "<br />");
I get the error when i try to add the "new {checked=true} part.
Cannot find an example of setting parameter in c# code online, cheers
I think checked is a keyword. Try putting an # in front:
new { #checked = true }

Resources