user2884405
user2884405

Reputation: 67

System.Data.OracleClient.OracleConnection does not contain a definition

I got this error CS1061: 'System.Data.OracleClient.OracleConnection' does not contain a definition for 'searchDBSet' and no extension method 'searchDBSet' accepting a first argument of type 'System.Data.OracleClient.OracleConnection' could be found (are you missing a using directive or an assembly reference?). I'm sure I have the reference which System.Data;and I think I have the issue with the inheritance because my code is not recognized.Can anyone please help solve this issue.Thank you

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Data.OracleClient;

public partial class users_Login : System.Web.UI.Page
{
    OracleConnection oc = new OracleConnection("Data Source=**;Persist Security Info=True;User ID=****;Password=****;Unicode=false");
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {

        int flag = 0;
        string user_name = loginUserName.Text;
        string password = loginPassword.Text;


        string qry = "select user_name,password from users where user_name='" + user_name + "' and password='" + password + "'";

        DataSet set = oc.searchDBSet(qry);

        foreach (DataRow dr in set.Tables[0].Rows)
        {
            flag = 1;
        }

        if (flag == 1)
        {
            FormsAuthentication.RedirectFromLoginPage(user_name, true);
        }
        else
        {
            lblMessage.Visible = true;
        }

    }

}


my class1 code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OracleClient;



public class Oracleconection
{
    string connectionString;
    private System.Data.OracleClient.OracleConnection connection;
    private System.Data.OracleClient.OracleDataAdapter adapter;
    private System.Data.OracleClient.OracleCommand command;

    public Oracleconection(string host, string dbname, string username, String password)
    {
        try
        {
            //this.connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST="+host+")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME="+dbname+")));User Id="+username+";Password="+password+";";
            this.connectionString = "Data Source=****;Persist Security Info=True;User ID=****;Password=****;Unicode=false";
            this.connection = new System.Data.OracleClient.OracleConnection(this.connectionString);
            this.connection.Open();
            this.command = connection.CreateCommand();
            Console.WriteLine("Connected");
        }
        catch (Exception e)
        {
            Console.WriteLine("Error while connecting:" + e.Message);
        }

    }
    public DataTable searchDB(string query)
    {
        DataTable table = new DataTable();
        try
        {
            this.command.CommandText = query;
            this.adapter = new System.Data.OracleClient.OracleDataAdapter(command);
            this.adapter.Fill(table);
        }
        catch (Exception e)
        {
            Console.Write("Error:" + e);
        }
        return table;
    }


    public DataSet searchDBSet(string query)
    {
        DataSet ds = new DataSet();
        try
        {
            this.command.CommandText = query;
            this.adapter = new System.Data.OracleClient.OracleDataAdapter(command);
            this.adapter.Fill(ds);
        }
        catch (Exception e)
        {
            Console.Write("Error:" + e);
        }
        return ds;
    }

    public int updateDB(string query)
    {
        try
        {
            this.command.CommandText = query;
            return this.command.ExecuteNonQuery();
        }
        catch (Exception e)
        {
            Console.Write("Error:" + e);
            return -1;
        }
    }


    public void close()
    {
        connection.Close();
    }
}

Upvotes: 0

Views: 3404

Answers (1)

Mihai Hantea
Mihai Hantea

Reputation: 1743

The class name is wrong.

You are doing this:

OracleConnection oc = new OracleConnection(...);

Change to your class:

Oracleconnection oc = new Oracleconnection(...);

Upvotes: 2

Related Questions