TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
naga jyothi
NA
62
110.7k
Problem in ExecuteUpdateQuery
Aug 7 2012 1:34 AM
//Presentation Layer code
if (datesvalidation () == false)
return;
SqlDataReader dr = null;
try
{
string str = "Select Companylocation,Companyname,Designation,Empid,Experience,Fromdate,Todate,Basicpay from EmpPreviousExpDetails where Empid='" + txtemployeeid.Text + "'";
dbConnection conn = new dbConnection();
dr = conn.SqlReaderQuery(str);
if (dr.Read())
{
BOL.bolEmpPreviousExpDetails EPED = new BOL.bolEmpPreviousExpDetails();
EPED.Companyname = txtcompanyname.Text;
EPED.Companylocation = txtcompanylocation.Text;
EPED.Designation = txtdesignation.Text;
EPED.Basicpay = Convert.ToDecimal(txtbasicpay.Text);
EPED.EmpId = txtemployeeid.Text;
EPED.Fromdate = Convert.ToDateTime(dtpFromDate.Value);
EPED.Todate = Convert.ToDateTime(dtpToDate.Value);
int experience = Convert.ToInt16(txtexperience.Text);
if (experience <= 0)
{
MessageBox.Show("Experience Should Be More Than Zero","Payroll",MessageBoxButtons.OK,MessageBoxIcon.Information );
}
else
{
EPED.Experience = Convert.ToString(txtexperience.Text);
MessageBox.Show("Records Successfully Updated","Payroll",MessageBoxButtons.OK,MessageBoxIcon.Information );
}
EPED.Update();
}
else
{
BOL.bolEmpPreviousExpDetails EPED = new BOL.bolEmpPreviousExpDetails();
EPED.Companyname = txtcompanyname.Text;
EPED.Companylocation = txtcompanylocation.Text;
EPED.Designation = txtdesignation.Text;
EPED.Basicpay = Convert.ToDecimal(txtbasicpay.Text);
EPED.EmpId = txtemployeeid.Text;
EPED.Fromdate = Convert.ToDateTime(dtpFromDate.Value);
EPED.Todate = Convert.ToDateTime(dtpToDate.Value);
int experience = Convert.ToInt16(txtexperience.Text);
if (experience <= 0)
{
MessageBox.Show("Experience Should Be More Than Zero","Payroll",MessageBoxButtons.OK,MessageBoxIcon.Information );
}
else
{
EPED.Experience = Convert.ToString(txtexperience.Text);
MessageBox.Show("Records Successfully Saved","Payroll",MessageBoxButtons.OK,MessageBoxIcon.Information );
}
EPED.Insert();
//clearPreviousDetails();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dr.Close();
}
//Data Access layer code
public bool Update(BOL.bolEmpPreviousExpDetails obj)
{
dbConnection conn =new dbConnection();
string sql = "update EmpPreviousExpDetails set Companyname=@Companyname,Companylocation=@Companylocation,Experience=@Experience,Designation=@Designation,Basicpay=@Basicpay,Fromdate=@Fromdate,Todate=@Todate where EmpId=@EmpId";
SqlParameter[] sqlParameters = new SqlParameter[8];
//sqlParameters[0] = new SqlParameter("@Srlno", SqlDbType.Int);
//sqlParameters[0].Value = obj.Srlno;
sqlParameters[0] = new SqlParameter("@EmpId", SqlDbType.VarChar);
sqlParameters[0].Value = obj.EmpId;
sqlParameters[1] = new SqlParameter("@Companyname", SqlDbType.VarChar);
sqlParameters[1].Value = obj.Companyname;
sqlParameters[2] = new SqlParameter("@Companylocation", SqlDbType.VarChar);
sqlParameters[2].Value = obj.Companylocation;
sqlParameters[3] = new SqlParameter("@Experience", SqlDbType.NVarChar);
sqlParameters[3].Value = obj.Experience;
sqlParameters[4] = new SqlParameter("@Designation", SqlDbType.VarChar);
sqlParameters[4].Value = obj.Designation;
sqlParameters[5] = new SqlParameter("@Basicpay", SqlDbType.Decimal);
sqlParameters[5].Value = obj.Basicpay;
sqlParameters[6] = new SqlParameter("@Fromdate", SqlDbType.DateTime);
sqlParameters[6].Value = obj.Fromdate;
sqlParameters[7] = new SqlParameter("@Todate", SqlDbType.DateTime);
sqlParameters[7].Value = obj.Todate;
return conn.executeUpdateQuery(sql, sqlParameters);
}
//Business Layer Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PayRoll.BOL
{
class bolEmpPreviousExpDetails
{
DAL.dalEmpPreviousExpDetails dalObj= new PayRoll.DAL.dalEmpPreviousExpDetails();
private Int32 m_Srlno;
private string m_EmpId;
private string m_Companyname;
private string m_Companylocation;
private string m_Experience;
private string m_Designation;
private Decimal m_Basicpay;
private DateTime m_Fromdate;
private DateTime m_Todate;
/// <constructor>
/// Constructor bolEmpPreviousExpDetails
/// </constructor>
public bolEmpPreviousExpDetails()
{
//Initialize the variable here
}
/// <summary>
/// ColumnName:Srlno
/// Data Type:int
/// Length:0
/// </summary>
public Int32 Srlno
{
get
{
return m_Srlno;
}
set
{
m_Srlno = value;
}
}
/// <summary>
/// ColumnName:Empid
/// Data Type:VarChar
/// Length:20
/// </summary>
public string EmpId
{
get
{
return m_EmpId;
}
set
{
if (value.Length > 20)
{
throw new InvalidData("The Empid is more length", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
m_EmpId = value;
}
}
/// <summary>
/// ColumnName:Companyname
/// Data Type:VarChar
/// Length:20
/// </summary>
public string Companyname
{
get
{
return m_Companyname;
}
set
{
if (value =="")
{
throw new InvalidData("Please Enter Company Name", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (value.Length > 20)
{
throw new InvalidData("The Companyname is more length", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
m_Companyname = value;
}
}
/// <summary>
/// ColumnName:Companylocation
/// Data Type:VarChar
/// Length:50
/// </summary>
public string Companylocation
{
get
{
return m_Companylocation;
}
set
{
if (value == "")
{
throw new InvalidData("Please Enter Company Location", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (value.Length > 50)
{
throw new InvalidData("The Companylocation is more length", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
m_Companylocation = value;
}
}
/// <summary>
/// ColumnName:Experience
/// Data Type:nVarChar
/// Length:20
/// </summary>
public string Experience
{
get
{
return m_Experience;
}
set
{
if (value == "")
{
throw new InvalidData("Please Enter Experience", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
m_Experience = value;
}
}
/// <summary>
/// ColumnName:Designation
/// Data Type:VarChar
/// Length:20
/// </summary>
public string Designation
{
get
{
return m_Designation;
}
set
{
if (value == "")
{
throw new InvalidData("Please Enter Designation", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (value.Length > 20)
{
throw new InvalidData("The Designation is more length", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
m_Designation = value;
}
}
/// <summary>
/// ColumnName:Basicpay
/// Data Type:decimal
/// Length:0
/// </summary>
public Decimal Basicpay
{
get
{
return m_Basicpay;
}
set
{
if (value == 0)
{
throw new InvalidData("Please Enter Basic Pay", "Payroll", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
m_Basicpay = value;
}
}
/// <summary>
/// ColumnName:Fromdate
/// Data Type:datetime
/// Length:0
/// </summary>
public DateTime Fromdate
{
get
{
return m_Fromdate;
}
set
{
m_Fromdate = value;
}
}
/// <summary>
/// ColumnName:Todate
/// Data Type:datetime
/// Length:0
/// </summary>
public DateTime Todate
{
get
{
return m_Todate;
}
set
{
m_Todate = value;
}
}
public bool Insert ()
{
dalObj.Insert(this);
return true;
}
public void get()
{
dalObj.get(this);
}
public bool Update()
{
dalObj.Update(this);
return true;
}
}
}
//dbconnection code
public bool executeUpdateQuery(String _query, SqlParameter[] sqlParameter)
{
SqlCommand myCommand = new SqlCommand();
try
{
myCommand.Connection = openConnection();
myCommand.CommandText = _query;
myCommand.Parameters.AddRange(sqlParameter);
myAdapter.UpdateCommand = myCommand;
myCommand.ExecuteNonQuery();
}
catch (SqlException e)
{
Console.Write("Error - Connection.executeUpdateQuery - Query: " + _query + " \nException: " + e.StackTrace.ToString());
return false;
}
finally
{
}
return true;
}
//Problem in ExecuteUpdateQuery so rectify the error
Reply
Answers (
1
)
Inherit a c# class in vb.net
how to pass grid row field values to another page text fields after clicking link buton?