locked
I am getting network path was not found error - when i post my webpage(Insert method) RRS feed

  • Question

  • User-945256609 posted

    I am getting error - when I insert a page to visual studio solution(to MS SQL database - in  local machine).

    Can somebody throw light on this.

    Employee page --- When I click the save method

    protected void AddSave_Click(object sender, EventArgs e)
    {
    EmployeeActions ea = new EmployeeActions();
    //int ID = Int32.Parse(lblID.Text);
    string EmpID = (string)txtEmpID.Text;
    string FirstName = (string)txtFirstName.Text;
    string LastName = (string)txtLastName.Text;
    string EmpFullName = (string)txtFullName.Text;
    string LoginName = (string)txtLoginName.Text;
    // string tmpPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1");
    //string Password = tmpPassword;
    string Email = (string)txtEmail.Text;
    string Gender = (string)rbGender.SelectedItem.Text;
    DateTime Dob = Convert.ToDateTime(txtDob.Text);
    string Marital = (string)rbMarital.SelectedItem.Text;
    DateTime Doj = Convert.ToDateTime(txtDoj.Text);
    ea.InsertEmployee(txtEmpID.Text, txtFirstName.Text, txtLastName.Text, txtFullName.Text, txtLoginName.Text, txtEmail.Text, rbGender.Text, Convert.ToDateTime(txtDob.Text), rbMarital.Text, Convert.ToDateTime(txtDoj.Text));
    Page.ClientScript.RegisterStartupScript(this.GetType(), "showMessage", "alert('Employee entry added successfully!');", true);

    ClearAll();
    AddSave.Visible = false;
    Add.Visible = true;
    btnEdit.Visible = true;
    RReadOnly();

    }

    Employee actions code:-

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using DataAccessLayer;

    namespace IFMR
    {
    public class EmployeeActions
    {

    DataAccess daAC = new DataAccess();

    public bool InsertEmployee(string EmpID, string FirstName, string LastName, string EmpFullName, string LoginName, string Email, string Gender, DateTime Dob, string Marital,DateTime Doj)
    {
    return daAC.InsertEmp(EmpID, FirstName, LastName,EmpFullName,LoginName,Email,Gender,Dob,Marital,Doj);

    }

    public bool UpdateEmployee(int ID,string EmpID, string FirstName, string LastName, string EmpFullName, string LoginName, string Email, string Gender, DateTime Dob, string Marital, DateTime Doj)
    {

    return daAC.UpdateEmp(ID,EmpID,FirstName,LastName,EmpFullName,LoginName,Email,Gender,Dob,Marital,Doj);
    }

    }
    }

    It calls the Data Access code

    Data access code is given below

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.SqlClient;
    using System.Data;
    using System.Configuration;

    //using System;
    //using System.Collections.Generic;
    //using System.Configuration;
    //using System.Data;
    //using System.Data.SqlClient;
    //using System.Linq;
    //using System.Text;
    //using
    ////using System.Web.Security;
    //


    namespace DataAccessLayer
    {
    public class DataAccess
    {

    public DataAccess()
    {


    }

    public bool InsertCust(string ID, string FirstName, string LastName)
    {
    SqlParameter parID = new SqlParameter("@ID", ID);
    SqlParameter parFirstname = new SqlParameter("@FirstName", FirstName);
    SqlParameter parLastname = new SqlParameter("@LastName", LastName);
    return Functions.ExecuteNonQuery("Customer", new System.Data.SqlClient.SqlParameter[] { parID, parFirstname, parLastname });
    }


    public bool InsertEmp(string EmpID, string FirstName, string LastName, string EmpFullName, string LoginName, string Email, string Gender, DateTime Dob, string Marital, DateTime Doj)
    {
    SqlParameter parEmpID = new SqlParameter("@EmpID", EmpID);
    SqlParameter parFirstName = new SqlParameter("@FirstName", FirstName);
    SqlParameter parLastName = new SqlParameter("@LastName", LastName);
    SqlParameter parEmpFullName = new SqlParameter("@EmpFullName", EmpFullName);
    SqlParameter parLoginName = new SqlParameter("@LoginName", LoginName);
    // SqlParameter parPassword = new SqlParameter("@Password", Password);
    SqlParameter parEmail = new SqlParameter("@Email", Email);
    SqlParameter parGender = new SqlParameter("@Gender", Gender);
    SqlParameter parDob = new SqlParameter("@Dob", Dob);
    SqlParameter parMarital = new SqlParameter("@Marital", Marital);
    SqlParameter parDoj = new SqlParameter("@Doj", Doj);
    return Functions.ExecuteNonQuery("spInsertRegisterNewEmployee", new System.Data.SqlClient.SqlParameter[] { parEmpID, parFirstName, parLastName, parEmpFullName, parLoginName, parEmail, parGender,parDob, parMarital,parDoj });


    }

    public bool UpdateEmp(int ID, string EmpID, string FirstName, string LastName, string EmpFullName, string LoginName, string Email, string Gender, DateTime Dob, string Marital, DateTime Doj)
    {
    SqlParameter parID = new SqlParameter("@ID", ID);
    SqlParameter parEmpID = new SqlParameter("@EmpID", EmpID);
    SqlParameter parFirstName = new SqlParameter("@FirstName", FirstName);
    SqlParameter parLastName = new SqlParameter("@LastName", LastName);
    SqlParameter parEmpFullName = new SqlParameter("@EmpFullName", EmpFullName);
    SqlParameter parLoginName = new SqlParameter("@LoginName", LoginName);
    //SqlParameter parPassword = new SqlParameter("@Password", Password);
    SqlParameter parEmail = new SqlParameter("@Email", Email);
    SqlParameter parGender = new SqlParameter("@Gender", Gender);
    SqlParameter parDob = new SqlParameter("@Dob", Dob);
    SqlParameter parMarital = new SqlParameter("@Marital", Marital);
    SqlParameter parDoj = new SqlParameter("@Doj", Doj);
    return Functions.ExecuteNonQuery("spUpdateEmployee", new System.Data.SqlClient.SqlParameter[] { parID, parEmpID, parFirstName, parLastName, parEmpFullName, parLoginName, parEmail, parGender, parDob, parMarital, parDoj });

    }

    public bool InsertPur(string PONumber, DateTime PODate, string ProductType, string SerialNoTagNo, DateTime PurchaseDate, DateTime InvoiceDate, string InvoiceNumber, int VendorID, string VendorName, string VendorAddress, string ProdDesc, int UnitPrice, int Quantity, int Amount, int TotalVal, string TeamName, string ApprovedBy, string OrderedBy, DateTime WarrantyStartDate)
    {
    SqlParameter parPONumber = new SqlParameter("@PONumber", PONumber);
    SqlParameter parPODate = new SqlParameter("@PODate", PODate);
    SqlParameter parProductType = new SqlParameter("@ProductType", ProductType);
    SqlParameter parSerialNoTagNo = new SqlParameter("@SerialNoTagNo", SerialNoTagNo);
    SqlParameter parPurchaseDate = new SqlParameter("@PurchaseDate", PurchaseDate);
    SqlParameter parInvoiceDate = new SqlParameter("@InvoiceDate", InvoiceDate);
    SqlParameter parInvoiceNumber = new SqlParameter("@InvoiceNumber", InvoiceNumber);
    SqlParameter parVendorID = new SqlParameter("@VendorID", VendorID);
    SqlParameter parVendorName = new SqlParameter("@VendorName", VendorName);
    SqlParameter parVendorAddress = new SqlParameter("@VendorAddress", VendorAddress);
    SqlParameter parProdDesc = new SqlParameter("@ProdDesc", ProdDesc);
    SqlParameter parUnitPrice = new SqlParameter("@UnitPrice", UnitPrice);
    SqlParameter parQuantity = new SqlParameter("@Quantity", Quantity);
    SqlParameter parAmount = new SqlParameter("@Amount", Amount);
    SqlParameter parTotalVal = new SqlParameter("@TotalVal", TotalVal);
    SqlParameter parTeamName = new SqlParameter("@TeamName", TeamName);
    SqlParameter parApprovedBy = new SqlParameter("@ApprovedBy", ApprovedBy);
    SqlParameter parOrderedBy = new SqlParameter("@OrderedBy", OrderedBy);
    SqlParameter parWarrantyStartDate = new SqlParameter("@WarrantyStartDate", WarrantyStartDate);
    //SqlParameter parWarrantyEndDate = new SqlParameter("@WarrantyEndDate", WarrantyEndDate);
    //SqlParameter parDiscountsOffersFreebies = new SqlParameter("@DiscountsOffersFreebies", DiscountsOffersFreebies);

    //, DateTime WarrantyEndDate, string DiscountsOffersFreebies ,parWarrantyEndDate,parDiscountsOffersFreebies


    return Functions.ExecuteNonQuery("spInsertPurchaseRegister", new System.Data.SqlClient.SqlParameter[] { parPONumber, parPODate, parProductType, parSerialNoTagNo, parPurchaseDate,parInvoiceDate, parInvoiceNumber, parVendorID,parVendorName,parVendorAddress,parProdDesc,parUnitPrice,parQuantity,parAmount,parTotalVal,parTeamName,parApprovedBy,parOrderedBy,parWarrantyStartDate });


    }

    }



    }

    data access call the common functions code - which gives network code in stack trace

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlClient;
    using System.Data;

    namespace DataAccessLayer
    {
    class Functions
    {


    static SqlConnection con = null;

    static Functions()
    {
    con = new SqlConnection(System.Web.HttpContext.GetGlobalResourceObject("ResourceConn", "connString").ToString());
    }
    public static bool ExecuteNonQuery(string CommandName, SqlParameter[] pars)
    {
    SqlCommand cmd = null;
    int res = 0;

    cmd = con.CreateCommand();

    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = CommandName;
    cmd.Parameters.AddRange(pars);

    try
    {
    con.Open();

    res = cmd.ExecuteNonQuery();

    con.Close();
    }

    catch (Exception ex)
    {
    throw;
    }

    finally
    {
    con.Close();
    cmd.Dispose();
    cmd = null;
    }

    if (res >= 1)
    {
    return true;
    }

    return false;


    }

    }
    }

    Saturday, March 23, 2019 10:52 AM

All replies