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

  • SEARCH
  • Home
  • 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 6353829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:28:41+00:00 2026-05-24T22:28:41+00:00

I am creating a web form on asp.net that will allow the end user

  • 0

I am creating a web form on asp.net that will allow the end user to assign multiple users bassed on a selected department to a quiz..

the database is mysql database since I use joomla

the tables on mysql are: jos_users_quizzes with the following columns:

id
quiz_id
user_id  

I have a second is called called

jos_dhruprofile with this columns

id
name
username
department 

I need to select all user ids from selected department and insert those id into the user_quizzes table.

I have two queries trying to to insert the first one which has the condition for selected department doesnt work while
the one without the were statement actually inserts, I get no errors , just the insertion doesnt go..

 string quizidselected = DropDownList1.SelectedValue;
   string deptselected = ListBox2.SelectedValue;
   OdbcCommand cmd = new OdbcCommand("INSERT INTO jos_jquarks_users_quizzes (user_id, quiz_id) SELECT uid, ' " + quizidselected + " ' FROM jos_dhruprofile WHERE department = ' " + deptselected.ToString() + " '"); 
          // OdbcCommand cmd = new OdbcCommand("INSERT INTO jos_jquarks_users_quizzes (user_id, quiz_id)    SELECT uid, ' " + quizidselected + " ' FROM dhruprofile "); 

THANKS IN ADVANCE FOR LOOKING MY CODE

Full code

Code from and ASP.NET form to insert ….

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Collections.Specialized;
using System.Text;
using System.Data;
using System.Data.Odbc;

public partial class _Default : System.Web.UI.Page 
{    
    protected void Page_Load(object sender, EventArgs e)
    {

    }

     private void InsertRecords(StringCollection sc)
    {
        string ConnectionString = @"driver={MySQL ODBC 5.1 Driver};server=appdevelsvr;database=xxxx;uid=xx;pwd=xx;";
        OdbcConnection conn = new OdbcConnection(ConnectionString);

        try
        {
            conn.Open();

            string quizidselected = DropDownList1.SelectedValue;
            string deptselected = ListBox2.SelectedValue;
            OdbcCommand cmd = new OdbcCommand("INSERT INTO jos_jquarks_users_quizzes (user_id, quiz_id) SELECT uid, ' " + quizidselected + " ' FROM jos_dhruprofile WHERE department = ' " + deptselected.ToString() + " '"); 
          // OdbcCommand cmd = new OdbcCommand("INSERT INTO jos_jquarks_users_quizzes (user_id, quiz_id)    SELECT uid, ' " + quizidselected + " ' FROM dhruprofile "); 

            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Script", "alert('Records Successfuly Saved!');", true);
            Response.Write(deptselected.ToString());
           // Response.Write(sql.ToString());

        }

        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);

        }

        finally
        {

            conn.Close();

        }

    }


    protected void Button1_Click(object sender, EventArgs e)
    {

        StringCollection sc = new StringCollection();

        foreach (ListItem item in ListBox2.Items)
        {

            if (item.Selected)
            {
                sc.Add(item.Text);

            }


        } 

                InsertRecords(sc);

    }


}
  • 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-24T22:28:43+00:00Added an answer on May 24, 2026 at 10:28 pm

    I am assuming that the query you want us to debug is the one with the where clause.

    Please set a breakpoint at the line where you are creating a new odbc command for cmd. You need to check the value of ‘deptselected’.

    Alternatively, you can debug.writeline the SQL statement and copy-paste it into a SQL query UI. Please run the select by itself. I think it will not return any rows because either ‘deptselected’ doesn’t exist in your table or ‘deptselected’ is empty.

    Also, two good programming pointers:-

    1). Use parameterized SQL statements instead of appending values into the string. Your code is vulnerable to a SQL injection attack. This is very bad.

    2). ‘deptselected’ is already a string, you do not need to ‘ToString’ it again.

    Hope this helps.

    Edit:-
    I just read the comments above. Do a select * (star) on that table and where someother_column = another_value to get the same row that you are interested in. Check the string lenght of your department column. Check if you have spaces at the beginning of the string or after.

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

Sidebar

Related Questions

I am creating a web form on asp.net that will allow the end user
I'm creating a multi-part web form in ASP.NET that uses Panels for the different
I'm creating a web service that'll be called from a web form in asp.net.
Greetings! I'm creating a web form prototype (ImageLaoder.aspx) that will return an image so
I am creating a web application using Form Authentication of Asp.Net with C# and
I'm creating a web form that requires an user to upload a file in
I am creating a web service for end users which will have a front-end
I am creating web page using asp.net. Is it possible to remove/hide the browsers
I am creating a Web application using ASP.NET MVC, and I'm trying to use
I have a simple web form that sends and email out via .NET C#.

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.