Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a feedback form where I want to show name which is inserted for n number of times.

My DataBase Have for example 9 time same names as feedback was inputted for that same person 9 times and I want to display it on result that common name

Please help me out to complete the code/solution and get the result.

SQL QUERY IS RUNNING PROPERLY IT IS SELECTING THE SINGLE DATA FROM DATABASE BUT HOW TO SHOW THIS ON WEBPAGE



public void cal_F2name()
{
       string oracledb = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP****))(****))(CONNECT_DATA =(SERVER = DEDICATED)(SID = ORCL));";
       OracleConnection conn = new OracleConnection(oracledb);
       conn.Open();

       OracleCommand cmd = new OracleCommand();
       cmd.Connection = conn;
       OracleDataAdapter da1 = new OracleDataAdapter();
       DataTable dt1 = new DataTable();
       DataSet ds1 = new DataSet();

       cmd.CommandText = "SELECT DISTINCT (F2NAME) FROM CMDC_FEEDBACK WHERE PRG_NAME ='" + cb_prg_name.SelectedValue + "'";

             da1.SelectCommand = cmd;
            da1.Fill(ds1);
            name = Convert.ToString(ds1.Tables[0].Rows[0][0].ToString());

             Label58.Text = String.Format("{0:0.00}",name);


       conn.Close();
}


What I have tried:

Please note in comments i have tried various method , I am just beginner

public void cal_F2name()
      {
          string oracledb = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = *******)(PORT = ****))(CONNECT_DATA =(SERVER = DEDICATED)(SID = ORCL))); User Id=****;Password=*****;";

          OracleConnection conn = new OracleConnection(oracledb);
          conn.Open();

          OracleCommand cmd = new OracleCommand();
          cmd.Connection = conn;
          OracleDataAdapter da1 = new OracleDataAdapter();
          DataTable dt1 = new DataTable();
          DataSet ds1 = new DataSet();

          cmd.CommandText = "SELECT DISTINCT (F2NAME) FROM CMDC_FEEDBACK WHERE PRG_NAME ='" + cb_prg_name.SelectedValue + "'";
          /*    cmd.ExecuteNonQuery();
             da1.Fill(dt1);
             d1.Datasource = dt1;
                da1.SelectCommand = cmd;
               da1.Fill(ds1);
               name = Convert.ToString(ds1.Tables[0].Rows[0][0].ToString());

               name=Convert.ToString(dr.Read());

               name = Convert.ToString(dt1.Rows[0][0]);

               name = Convert.ToString(cmd.ExecuteReader());

                Label58.Text = String.Format("{0:0.00}",name);

             OracleDataReader reader = cmd.ExecuteReader();

             reader.Read();

             Label58.Text = reader.ToString();

               OracleDataReader reader = cmd.ExecuteReader();
               reader.Read();
               if (reader.HasRows)
               {
                   Label58.Text = reader["F2NAME"].ToString();
               }
           *
           *  */


          conn.Close();

      }
Posted
Updated 8-Jun-22 22:50pm
v3

1 solution

You haven't told us what the problem you are meeting is, but ... don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900