i have making one projects related to builders application....in that i have made one web page for cement data .........now i have showing all this files..
1)aspx.cs file......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace astha_developers
{
public partial class cementdata : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
loaddatatogrid();
}
}
protected void loaddatatogrid()
{
GridView1.DataSource = cement_class.select();
GridView1.DataBind();
}
protected void btnsave_Click(object sender, EventArgs e)
{
cement_class c = new cement_class();
c.brandname = Convert.ToString(txtbrandname.Text);
c.suppliername = Convert.ToString(txtsuppname.Text);
c.cementorderdate = Convert.ToDateTime(txtorderdate.Text);
c.numberofbags = Convert.ToInt16(txtnoofbags.Text);
c.rateperbag = Convert.ToDouble(txtrate.Text);
c.amount = Convert.ToDouble(txtamount.Text);
c.recievedate = Convert.ToDateTime(txtrecieveddate.Text);
c.noofbagrecieved = Convert.ToInt16(txtrecievedbags.Text);
c.openingstock = Convert.ToInt16(txtopeningstock.Text);
c.usedstock = Convert.ToInt16(txtusedstock.Text);
c.closedstock = Convert.ToInt16(txtclosingstock.Text);
int result = c.insert();
loaddatatogrid();
clearall();
}
protected void btnedit_Click(object sender, EventArgs e)
{
cement_class c = new cement_class();
c.brandname = Convert.ToString(txtbrandname.Text);
c.suppliername = Convert.ToString(txtsuppname.Text);
c.cementorderdate = Convert.ToDateTime(txtorderdate.Text);
c.numberofbags = Convert.ToInt16(txtnoofbags.Text);
c.rateperbag = Convert.ToDouble(txtrate.Text);
c.amount = Convert.ToDouble(txtamount.Text);
c.recievedate = Convert.ToDateTime(txtrecieveddate.Text);
c.noofbagrecieved = Convert.ToInt16(txtrecievedbags.Text);
c.openingstock = Convert.ToInt16(txtopeningstock.Text);
c.usedstock = Convert.ToInt16(txtusedstock.Text);
c.closedstock = Convert.ToInt16(txtclosingstock.Text);
int result = c.update(Convert.ToInt32(txtid.Text));
loaddatatogrid();
clearall();
}
protected void btndelete_Click(object sender, EventArgs e)
{
cement_class c = new cement_class();
c.delete(Convert.ToInt32(txtid.Text));
loaddatatogrid();
clearall();
}
protected void btnreset_Click(object sender, EventArgs e)
{
clearall();
}
protected void clearall()
{
txtid.Text = "";
txtbrandname.Text = "";
txtsuppname.Text = "";
txtorderdate.Text = "";
txtnoofbags.Text = "";
txtrate.Text = "";
txtamount.Text = "";
txtrecieveddate.Text = "";
txtrecievedbags.Text = "";
txtopeningstock.Text = "";
txtusedstock.Text = "";
txtclosingstock.Text = "";
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int i = GridView1.SelectedRow.RowIndex;
txtid.Text = GridView1.Rows[i].Cells[1].Text;
txtbrandname.Text = GridView1.Rows[i].Cells[2].Text;
txtsuppname.Text = GridView1.Rows[i].Cells[3].Text;
txtorderdate.Text = GridView1.Rows[i].Cells[4].Text;
txtnoofbags.Text = GridView1.Rows[i].Cells[5].Text;
txtrate.Text = GridView1.Rows[i].Cells[6].Text;
txtamount.Text = GridView1.Rows[i].Cells[7].Text;
txtrecieveddate.Text = GridView1.Rows[i].Cells[8].Text;
txtrecievedbags.Text = GridView1.Rows[i].Cells[9].Text;
txtopeningstock.Text = GridView1.Rows[i].Cells[10].Text;
txtusedstock.Text = GridView1.Rows[i].Cells[11].Text;
txtclosingstock.Text = GridView1.Rows[i].Cells[12].Text;
}
}
}
2)class file.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
namespace astha_developers
{
public class cement_class
{
private int _cid = 0;
private string _brandname = "";
private string _suppliername = "";
private DateTime _cementorderdate;
private int _numerofbags = 0;
private double _rateperbag = 0;
private double _amount = 0;
private DateTime _recieveddate;
private int _noofbagrecieved = 0;
private int _openingstock = 0;
private int _usedstock = 0;
private int _closedstock = 0;
public int cid
{
get
{
return _cid;
}
set
{
_cid = value;
}
}
public string brandname
{
get
{
return _brandname;
}
set
{
_brandname = value;
}
}
public string suppliername
{
get
{
return _suppliername;
}
set
{
_suppliername = value;
}
}
public DateTime cementorderdate
{
get
{
return _cementorderdate;
}
set
{
_cementorderdate = value;
}
}
public int numberofbags
{
get
{
return _numerofbags;
}
set
{
_numerofbags = value;
}
}
public double rateperbag
{
get
{
return _rateperbag;
}
set
{
_rateperbag = value;
}
}
public double amount
{
get
{
return _amount;
}
set
{
_amount = value;
}
}
public DateTime recievedate
{
get
{
return _recieveddate;
}
set
{
_recieveddate = value;
}
}
public int noofbagrecieved
{
get
{
return _noofbagrecieved;
}
set
{
_noofbagrecieved = value;
}
}
public int openingstock
{
get
{
return _openingstock;
}
set
{
_openingstock = value;
}
}
public int usedstock
{
get
{
return _usedstock;
}
set
{
_usedstock = value;
}
}
public int closedstock
{
get
{
return _closedstock;
}
set
{
_closedstock = value;
}
}
public int insert()
{
SqlParameter[] param = new SqlParameter[12];
param[0] = new SqlParameter("@brandname", SqlDbType.VarChar);
param[0].Value = _brandname;
param[1] = new SqlParameter("@mode", SqlDbType.VarChar);
param[1].Value = "insert";
param[2] = new SqlParameter("@suppliername", SqlDbType.VarChar);
param[2].Value = _suppliername;
param[3] = new SqlParameter("@cementorderdate", SqlDbType.DateTime);
param[3].Value = _cementorderdate;
param[4] = new SqlParameter("@numberofbags ", SqlDbType.Int);
param[4].Value = _numerofbags;
param[5] = new SqlParameter("@rateperbag ", SqlDbType.Float);
param[5].Value =_rateperbag;
param[6] = new SqlParameter("@amount ", SqlDbType.Float);
param[6].Value = _amount;
param[7] = new SqlParameter("@recievedate", SqlDbType.DateTime);
param[7].Value = _recieveddate;
param[8] = new SqlParameter("@noofbagrecieved ", SqlDbType.Int);
param[8].Value = _noofbagrecieved;
param[9] = new SqlParameter("@openingstock ", SqlDbType.Int);
param[9].Value = _openingstock;
param[10] = new SqlParameter("@usedstock ", SqlDbType.Int);
param[10].Value = _usedstock;
param[11] = new SqlParameter("@closedstock ", SqlDbType.Int);
param[11].Value = _closedstock;
int result = astha_developers.commondata.ExecuteStatement("insertcement", CommandType.StoredProcedure, param);
return result;
}
public int update(int id)
{
SqlParameter[] param = new SqlParameter[13];
param[0] = new SqlParameter("@cid", SqlDbType.Int);
param[0].Value = _cid;
param[1] = new SqlParameter("@brandname", SqlDbType.VarChar);
param[1].Value = _brandname;
param[2] = new SqlParameter("@mode", SqlDbType.VarChar);
param[2].Value = "insert";
param[3] = new SqlParameter("@suppliername", SqlDbType.VarChar);
param[3].Value = _suppliername;
param[4] = new SqlParameter("@cementorderdate", SqlDbType.DateTime);
param[4].Value = _cementorderdate;
param[5] = new SqlParameter("@numberofbags ", SqlDbType.Int);
param[5].Value = _numerofbags;
param[6] = new SqlParameter("@rateperbag ", SqlDbType.Float);
param[6].Value = _rateperbag;
param[7] = new SqlParameter("@amount ", SqlDbType.Float);
param[7].Value = _amount;
param[8] = new SqlParameter("@recievedate", SqlDbType.DateTime);
param[8].Value = _recieveddate;
param[9] = new SqlParameter("@noofbagrecieved ", SqlDbType.Int);
param[9].Value = _noofbagrecieved;
param[10] = new SqlParameter("@openingstock ", SqlDbType.Int);
param[10].Value = _openingstock;
param[11] = new SqlParameter("@usedstock ", SqlDbType.Int);
param[11].Value = _usedstock;
param[12] = new SqlParameter("@closedstock ", SqlDbType.Int);
param[12].Value = _closedstock;
int result = astha_developers.commondata.ExecuteStatement("updatecement", CommandType.StoredProcedure, param);
return result;
}
public void delete(int id)
{
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@cid", SqlDbType.Int);
param[0].Value = _cid;
param[1] = new SqlParameter("@mode", SqlDbType.VarChar);
param[1].Value = "delete";
int result =astha_developers.commondata.ExecuteStatement("deletecement", CommandType.StoredProcedure, param);
}
public static DataTable select()
{
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@mode", SqlDbType.VarChar);
param[0].Value = "select";
DataTable dt = astha_developers.commondata.GetDataTable("selctcement", CommandType.StoredProcedure, param);
return dt;
}
}
}
3)class file for connection with database..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
namespace astha_developers
{
public class commondata
{
public static string Connstr = ConfigurationManager.ConnectionStrings["astha_developers"].ToString();
public static int ExecuteStatement(String command, CommandType cmdType, SqlParameter[] parameters)
{
SqlConnection Conn = new SqlConnection();
try
{
Conn = new SqlConnection(Connstr);
Conn.Open();
int result = -1;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = cmdType;
cmd.CommandText = command;
cmd.Connection = Conn;
if (parameters != null)
{
foreach (SqlParameter param in parameters)
{
cmd.Parameters.Add(param);
}
}
result = Int32.Parse(cmd.ExecuteNonQuery().ToString());
Conn.Close();
return result;
}
catch (Exception ex)
{
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
throw new Exception(ex.Message);
}
}
public static DataTable GetDataTable(String command, CommandType cmdType, SqlParameter[] parameters)
{
SqlConnection Conn = new SqlConnection();
try
{
Conn = new SqlConnection(Connstr);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = cmdType;
cmd.CommandText = command;
cmd.Connection = Conn;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0];
}
else
{
return null;
}
}
catch (Exception ex)
{
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
throw new Exception(ex.Message);
}
}
}
}
and store procedures....for inserting the data ..
ALTER procedure [dbo].[insertcement] @brandname varchar(50),@suppliername varchar(50),@cementorderdate datetime,@noofbags int,@rateperbag float,@amount float,@recieveddate datetime,@nofbagsrecieved int,@openingstock int,@usedstock int,@closedstock int
as
insert into cementdetails(brandname,suppliername,cementorderdate ,noofbags ,rateperbag ,amount ,recieveddate,noofbagsrecieved ,openingstock ,usedstock ,closedstock) values(@brandname,@suppliername,@cementorderdate ,@noofbags ,@rateperbag ,@amount ,@recieveddate,@nofbagsrecieved ,@openingstock ,@usedstock ,@closedstock)
but it shows me error like..
Procedure or function insertcement has too many arguments specified...
so help me to find it out and succesfully insert the data...
thankss..