im doing a project on insert update and delete using three tier architecture...
coming to insert it was working fine and coming to update and delete... im getting an error called... "cannot find column[...]"
the code for BLL library is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;
namespace BLL
{
public class LIB2
{
string code;
string language;
DataRow drl;
public LIB2()
{ }
public string pcode
{
set
{
code = value;
}
get
{
return code;
}
}
public string planguage
{
set
{
language = value;
}
get
{
return language;
}
}
LIB1 l = new LIB1();
public void insert()
{
drl = l.ds.Tables[0].NewRow();
drl[0] = code;
drl[1] = language;
l.ds.Tables[0].Rows.Add(drl);
}
public void update()
{
drl = l.ds.Tables[0].Select("code=" + code)[0];
drl[0] = code;
drl[1] = language;
}
public void delete()
{
drl = l.ds.Tables[0].Select("code=" + code)[0];
drl.Delete();
}
public void bind()
{
l.Bind();
}
public DataTable gettabledata()
{
return l.ds.Tables[0];
}
}
}
and code for DLL library is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
public class LIB1
{
SqlConnection con = new SqlConnection("Persist Security Info=True;User ID=*****;Password=****;Initial Catalog=chaitanya;Server=PC01");
SqlDataAdapter da;
public DataSet ds;
SqlCommandBuilder bdr;
public LIB1()
{
da = new SqlDataAdapter("select * from languages", con);
ds = new DataSet();
da.Fill(ds, "languages");
da.FillSchema(ds, SchemaType.Source, "languages");
bdr = new SqlCommandBuilder(da);
}
public void Bind()
{
da.Update(ds, "languages");
}
}
}
and code for Presentation layer is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
namespace ttr
{
public partial class tta : UserControl
{
LIB2 l = new LIB2();
public tta()
{
InitializeComponent();
}
public void bind()
{
l.bind();
}
private void tta_Load(object sender, EventArgs e)
{
grid.DataSource = l.gettabledata();
}
private void Create_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("Please enter all the details", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Focus();
return;
}
else
{
try
{
l.pcode = textBox1.Text;
l.planguage = textBox2.Text;
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
l.insert();
l.bind();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void Update_Click(object sender, EventArgs e)
{
l.pcode = textBox1.Text;
l.planguage = textBox2.Text;
l.update();
l.bind();
}
private void Delete_Click(object sender, EventArgs e)
{
l.pcode = textBox1.Text;
l.delete();
l.bind();
}
private void New_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
}
private void grid_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
DataGridViewRow row = this.grid.Rows[e.RowIndex];
grid.ReadOnly = true;
textBox1.Text = row.Cells["code"].Value.ToString();
textBox2.Text = row.Cells["language"].Value.ToString();
}
}
}
}
these are the code snippets i wrote..... insert command is working very fine but i got head ace with the update and delete...can you guys anyone help me in this.....