Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:03:43+00:00 2026-05-24T09:03:43+00:00

My current best code is: string delNonQuery = DELETE FROM + Settings.DataSource + WHERE

  • 0

My current best code is:

string delNonQuery = "DELETE FROM " + Settings.DataSource + " WHERE @keycolumn=@keyuid";

SqlCommand cmd = new SqlCommand(delNonQuery,readerConn);
SqlParameter kc = new SqlParameter("keycolumn", SqlDbType.VarChar);
SqlParameter key = new SqlParameter("keyuid", SqlDbType.VarChar);
cmd.Parameters.Add(kc).Value = Settings.KeyColumn;
cmd.Parameters.Add(key).Value = Page.Request["key"].ToString().Trim();

readerConn.Open();
cmd.ExecuteScalar();
readerConn.Close();

This executes but affects a whopping zero rows. If I change the SqlDbType on keyuid to UniqueIdentifier it just ends up with me getting a dozen variations on “failed to convert character string into uniqueidentifier”. I have to use a parameterized query for data cleanliness, I’m just really stuck as to how…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:03:45+00:00Added an answer on May 24, 2026 at 9:03 am

    You can’t specify a parameter for a column name – you need to concatenate it the same way you do for the table name.

    This:

    "DELETE FROM " + Settings.DataSource + " WHERE @keycolumn=@keyuid"
    

    Should change to:

    "DELETE FROM " + Settings.DataSource + " WHERE " + Settings.KeyColumn + " =@keyuid"
    

    Though I would probably write it as:

    string delNonQuery = string.Format("DELETE FROM {0} WHERE {1} = @keyuid", 
                                       Settings.DataSource, 
                                       Settings.KeyColumn);
    

    For completeness sake, I will mention that this is open to SQL injection. You need to make sure your Settings values are clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are the current best practices in the Rails world for displaying a calendar
Could someone please advise the current best practice around Date and Calendar types. When
I'm learning Grails/GORM and as I've understood it the current best practice is not
What are the best current libraries/methods to authenticate users without the use of a
Whats the best way to get the current time (HH:MM:SS) using Objective-C. I would
What is the best way to generate a current datestamp in Java? YYYY-MM-DD:hh-mm-ss
(MFC Question) What's the best way to determine the current displayed client area in
What is the best way to get the current system time milliseconds?
What is the best method to determine if the current time is AM or
What is the best way to retrieve the current date? Currently I am storing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.