Link to home
Start Free TrialLog in
Avatar of ahadee
ahadee

asked on

help fix an error in asp

i have posted a code below that seems to be working half way. i am a newbie to asp and therefore need it to be explained as simplistically as possible.

the problem is: as u will see there are data that has to go in multiple db's. the data seems to go into the first 2 db's and then jumps to the exception. pls assist.
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using jb_datamanipulate;
using System.Web.Mail;
using Winthusiasm.HtmlEditor;

public partial class superadmin_Job_master : System.Web.UI.Page
{
    cscSQLdata objData = new cscSQLdata();
    string strConnection = "";

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
        {
        //    bindCountry();
        //    bindCountry2();
        //    bindCity();
        //    bindCity2();
        }
    }
    

protected void  btnApply_Click(object sender, EventArgs e)
{
    try
    {
        strConnection = ConfigurationManager.ConnectionStrings["ConnStringpkt"].ToString().Trim();
        DataSet ds = new DataSet();
        objData.connectionstring = strConnection;

        string strPassword;
        strPassword = RandomNumber(1000, 9999).ToString();


        ds = objData.metcscdataset("select * from Profile where LoginId = '" + txtLoginID.Text.ToString() + "'", "jobportal");
          if ((ds.Tables[0].Rows.Count > 0))
          {
              divmsg.Visible = true;
              lblmsg.Text = "Sorry! Already UserName exist, Username must be unique";
          }
          else
          {
              DataSet ds2 = new DataSet();
              DataSet ds3 = new DataSet();
              DataSet ds4 = new DataSet();
              DataSet ds5 = new DataSet();
              
              int MemID = 0;

              objData.metcscgetstring("Insert into Profile(LoginId, Password, EMailId, FName, LName, MName, FatherName, MotherName, Address, CityId, CountryId, ZIP, DOB, Sex, Nationality) values('" + txtLoginID.Text.ToString() + "','" + strPassword.ToString() + "','" + txtEmail.Text.ToString() + "','" + txtFirstName.Text.ToString() + "', '" + txtLastName.Text.ToString() + "', '" + txtMiddleName.Text.ToString() + "', '" + txtFather.Text.ToString() + "', '" + txtMother.Text.ToString() + "', '" + txtAddress.Text.ToString() + "','" + int.Parse(ddlCity.SelectedValue.ToString()) + "', '" + int.Parse(ddlCountry.SelectedValue.ToString()) + "', '" + txtZip.Text.ToString() + "', '" + txtDOB.Text.ToString() + "', '" + int.Parse(ddlGender.SelectedValue.ToString()) + "', '" + int.Parse(ddlNationality.SelectedValue.ToString()) + "')");
              //'" + txtRelegion.Text.ToString() + "'
              
              ds2 = objData.metcscdataset("Select max(MemId) as mid from Profile", "jobportal");
              if (ds2.Tables[0].Rows.Count > 0)
              {

                  MemID = int.Parse(ds2.Tables[0].Rows[0]["mid"].ToString());
              }
              MemID = 0;
              objData.metcscgetstring("Insert into Acedemics(MemId, FromDt, ToDt, FinalResultDt, Grade, Institute, University, Percentage) values(" + MemID + ",'" + txtFromDt.Text.ToString() + "', '" + txtToDt.Text.ToString() + "', '" + txtFinalResult.Text.ToString() + "', '" + int.Parse(txtGPA.Text.ToString()) + "', '" + txtInstitute.Text.ToString() + "', '" + txtUniversity.Text.ToString() + "', '" + int.Parse(txtPercentage.Text.ToString()) + "')");
              
              ds3 = objData.metcscdataset("Select max(MemId) as mid from Academics", "jobportal");
              if (ds3.Tables[0].Rows.Count > 0)
              {

                  MemID = int.Parse(ds3.Tables[0].Rows[0]["mid"].ToString());
              }

              objData.metcscgetstring("Insert into ExpDetails(MemId, CompanyName, CompanyAddess, TechWorked, FromDt, ToDt, LastPosHeld) values(" + MemID + ",'" + ddlCompName.SelectedItem.ToString() + "', '" + txtCompanyAddress.Text.ToString() + "', '" + ddlTechnology.SelectedItem.ToString() + "', '" + txtStDt2.Text.ToString() + "', '" + txtStDt3.Text.ToString() + "', '" + int.Parse(ddlRole.SelectedValue.ToString()) + "')");

              int ExpId = 0;

              ds4 = objData.metcscdataset("Select max(ExpId) as expid from ExpDetails", "jobportal");
              if (ds4.Tables[0].Rows.Count > 0)
              {

                  ExpId = int.Parse(ds4.Tables[0].Rows[0]["expid"].ToString());
              }

              objData.metcscgetstring("Insert into WorkDetails(ExpId, PrjName, PrjDesc, RolePlayed, TechUsed) values(" + ExpId + ",'" + txtProject.Text.ToString() + "', '" + txtProjectDesc.Text.ToString() + "', '" + ddlRole.SelectedValue.ToString() + "', '" + ddlTechnology.SelectedItem.ToString() + "')");



              objData.metcscgetstring("Insert into EmployersLocation(CompanyId, Address, CityId, ContryId) values('" + int.Parse(ddlCompName.SelectedValue.ToString()) + "', '" + txtCompanyAddress.Text.ToString() + "','" + int.Parse(ddlCity2.SelectedValue.ToString()) + "', '" + int.Parse(ddlCountry2.SelectedValue.ToString()) + "')");

              int CompanyId = 0;

              ds3 = objData.metcscdataset("select CompanyId as cid from EmployersLocation where EmlrLocId =(select max(EmlrLocId) from EmployersLocation);", "jobportal");
              if (ds3.Tables[0].Rows.Count > 0)
              {

                  CompanyId = int.Parse(ds3.Tables[0].Rows[0]["cid"].ToString());
              }
              
              objData.metcscgetstring("Insert into Employers(CompanyId, CompanyName, Address, CityId, ContryId) values(" + CompanyId + ", '" + ddlCompName.SelectedItem.ToString() + "','" + txtCompanyAddress.Text.ToString() + "'," + int.Parse(ddlCity2.SelectedValue.ToString()) + ", " + int.Parse(ddlCountry2.SelectedValue.ToString()) + ")");

          }

    }

    catch (Exception ex)
    {
        divmsg.Visible = true;
        lblmsg.Text = ex.ToString();
    }
}
private int RandomNumber(int min, int max)
{ 
    Random random = new Random();
    return random.Next(min, max);
}
//void bindCountry()
//{


//    //DataTable dt = new DataTable();
//    strConnection = ConfigurationManager.ConnectionStrings["ConnStringpkt"].ToString().Trim();
//    DataSet ds = new DataSet();
//    objData.connectionstring = strConnection;

//    ds = objData.metcscdataset("select * from Profile", "jobportal");

//    if ((ds.Tables[0].Rows.Count > 0))
//    {
//        ddlCountry.DataSource = ds.Tables[0].DefaultView;
//        ddlCountry.DataValueField = "CountryId";
//        ddlCountry.DataTextField = ddlCountry.SelectedItem.ToString();
//        ddlCountry.DataBind();
//        ddlCountry.Items.Insert(0, new ListItem("(Select)", "0"));
//        // u can also fetch data from this dataset aslo
//    }
//    else
//    {
//        ddlCountry.DataSource = null;
//        ddlCountry.DataBind();
//    }
//}

//void bindCountry2()
//{


//    //DataTable dt = new DataTable();
//    strConnection = ConfigurationManager.ConnectionStrings["ConnStringpkt"].ToString().Trim();
//    DataSet ds = new DataSet();
//    objData.connectionstring = strConnection;

//    ds = objData.metcscdataset("select * from EmployersLocation", "jobportal");

//    if ((ds.Tables[0].Rows.Count > 0))
//    {
//        ddlCountry2.DataSource = ds.Tables[0].DefaultView;
//        ddlCountry2.DataValueField = "ContryId";
//        ddlCountry2.DataTextField = ddlCountry2.SelectedItem.ToString();
//        ddlCountry2.DataBind();
//        ddlCountry2.Items.Insert(0, new ListItem("(Select)", "0"));
//        // u can also fetch data from this dataset aslo
//    }
//    else
//    {
//        ddlCountry2.DataSource = null;
//        ddlCountry2.DataBind();
//    }
//}
//void bindCity()
//{


//    //DataTable dt = new DataTable();
//    strConnection = ConfigurationManager.ConnectionStrings["ConnStringpkt"].ToString().Trim();
//    DataSet ds = new DataSet();
//    objData.connectionstring = strConnection;

//    ds = objData.metcscdataset("select * from Profile", "jobportal");

//    if ((ds.Tables[0].Rows.Count > 0))
//    {
//        ddlCity.DataSource = ds.Tables[0].DefaultView;
//        ddlCity.DataValueField = "CityId";
//        ddlCity.DataTextField = ddlCity.SelectedItem.ToString();
//        ddlCity.DataBind();
//        ddlCity.Items.Insert(0, new ListItem("(Select)", "0"));
//        // u can also fetch data from this dataset aslo
//    }
//    else
//    {
//        ddlCity.DataSource = null;
//        ddlCity.DataBind();
//    }
//}

//void bindCity2()
//{


//    //DataTable dt = new DataTable();
//    strConnection = ConfigurationManager.ConnectionStrings["ConnStringpkt"].ToString().Trim();
//    DataSet ds = new DataSet();
//    objData.connectionstring = strConnection;

//    ds = objData.metcscdataset("select * from EmployersLocation", "jobportal");

//    if ((ds.Tables[0].Rows.Count > 0))
//    {
//        ddlCity2.DataSource = ds.Tables[0].DefaultView;
//        ddlCity2.DataValueField = "CityId";
//        ddlCity2.DataTextField = ddlCity.SelectedItem.ToString();
//        ddlCity2.DataBind();
//        ddlCity2.Items.Insert(0, new ListItem("(Select)", "0"));
//        // u can also fetch data from this dataset aslo
//    }
//    else
//    {
//        ddlCity2.DataSource = null;
//        ddlCity2.DataBind();
//    }
//}

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ahadee
ahadee

ASKER

@informaniac

Well, the thing is, there are no build errors, per se. It just does'nt do what its supposed to do. that inserting the data into the tables (excepting the 1st 2 tables).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ahadee

ASKER

The problems were mostly in the conversions from string to int...though i don't know why it debugged without errors!