Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Following is my code file.

I am getting the following error:
The type or namespace name 'dbconnection' could not be found (are you missing a using directive or an assembly reference?)<br />

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;

public partial class Enquiry_Ind : System.Web.UI.Page
{
    dbconnection dbcon = new dbconnection();

    protected void Page_Load(object sender, EventArgs e)
    {      
        
    }
    protected void Ind_Submit_Click(object sender, EventArgs e)
    {
        dbcon.opencon();
       
        SqlCommand cmd = new SqlCommand("Insert into Indivisual(Name,Age,Mobile_No,Email_Id,Occupation,Location) values('" + Ind_Name.Text + "','" + Ind_Age.Text + "','" + Ind_Mobil_No.Text + "', '" + Ind_Email_Id.Text + "'  ,'" + Ind_Occ.SelectedItem.Value + "','"+Ind_Loc.SelectedItem.Value+"')", dbcon.con);
        cmd.ExecuteNonQuery();
        dbcon.closecon();
        SqlCommand cmd1 = new SqlCommand("select max(id) from login_master", dbcon.con );
        int id1 = Convert.ToInt32(cmd1.ExecuteScalar());
        id1 = id1 + 1;
        string name = Ind_Name.Text;
        string user_id;
        string occ = Ind_Occ.SelectedValue;

        if (Ind_Occ.SelectedValue == "Business/Entrepreneur")
        {
            occ = occ.Substring(0, 2) + occ.Substring(9, 2);
        }
        else if (Ind_Occ.SelectedValue == "Service-Private")
        {
            occ = occ.Substring(0, 2) + occ.Substring(8, 2);
        }
        else if (Ind_Occ.SelectedValue == "HouseWife")
        {
            occ = occ.Substring(0, 2) + occ.Substring(5, 2);
        }
        else if (Ind_Occ.SelectedValue == "Service-Govt/Psu/Defence/Army/Armed Force/Civil Services")
        {
            occ = occ.Substring(0, 2) + occ.Substring(7, 2);
        }
        else
        {
            occ = occ.Substring(0, 4);
        }
        user_id = name.Substring(0, 3) + occ + id1;
        string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?_-";
        char[] chars = new char[6];
        Random rd = new Random();
        for (int i = 0; i < 6; i++)
        {
            chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
        }
        string individual = "Individual";
        string pass = new string(chars);
        Session["user"] = user_id.ToString();
        Session["passwd"] = pass;
        SqlCommand cmd2 = new SqlCommand("INSERT INTO login_master (id,User_id,password,user_type) VALUES ( '" + id1 + "' , '" + user_id + "', '" + pass + "', '" + individual + "' )", dbcon .con );
        cmd2.ExecuteNonQuery();
        Session.Add("LoginID", user_id);
        Session.Add("Password", pass);
        Server.Transfer("~/Enquiry/Thank u.aspx");
        
    
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}



[Edited]Code is wrapped in "pre" tags[/Edited]
Posted
Updated 20-Apr-11 21:39pm
v3
Comments
Dalek Dave 21-Apr-11 3:39am    
Edited for Readability.

try this

SqlConnection Con = new SqlConnection("Your Connection String");
 
Share this answer
 
v2
Comments
RaviRanjanKr 21-Apr-11 2:36am    
Good Solution! My 5 :)
Dalek Dave 21-Apr-11 3:39am    
Good Call.
I am eager to know why are you using dbconnection whatever as Mahen suggested you should import System.Data.dll in your project and then you need to use SqlConnection Class instead of dbconnection.
take a look there-[SqlConnection Class][^] for more details.
 
Share this answer
 
Comments
Dalek Dave 21-Apr-11 3:39am    
Sage Advice
From the error you got to add the reference System.Data.Common

System.Data.Common.DbConnection dbcon = System.Data.Common.DbConnection();
 
Share this answer
 
Comments
Dalek Dave 21-Apr-11 3:40am    
Good Answer.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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