DJRudeBwoy 0 Newbie Poster

I did all this code for a form that inputs, delets, updates, and views data in a database and everything works but i keep getting errors that my update and delete isn't working and it's some kind of exception.

here's the entire code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace RudeBwoy_Entertainment_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


System.Data.SqlClient.SqlConnection con;
DataSet ds1;
System.Data.SqlClient.SqlDataAdapter da;
int MaxRows = 0;
int inc = 0;


private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'clientBaseDataSet.tblClients' table. You can move, or remove it, as needed.
this.tblClientsTableAdapter.Fill(this.clientBaseDataSet.tblClients);
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\ClientBase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
ds1 = new DataSet();


con.Open();


string sql = "SELECT * From tblClients";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
da.Fill(ds1, "Clients");


con.Close();


}


private void btnSave_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);



DataRow dRow = ds1.Tables["Clients"].NewRow();


dRow[0] = client_IDTextBox.Text;
dRow[1] = first_NameTextBox.Text;
dRow[2] = last_NameTextBox.Text;
dRow[3] = primary_ContactTextBox.Text;
dRow[4] = secondary_ContactTextBox.Text;
dRow[5] = date_of_EventTextBox.Text;
dRow[6] = venueTextBox.Text;
dRow[7] = number_of_GuestsTextBox.Text;
dRow[8] = length_of_eventTextBox.Text;
dRow[9] = equipmentTextBox.Text;
dRow[10] = priceTextBox.Text;
dRow[11] = downpaymentTextBox.Text;
dRow[12] = balanceTextBox.Text;
dRow[13] = commentsTextBox.Text;


ds1.Tables["Clients"].Rows.Add(dRow);


MaxRows = MaxRows + 1;
inc = MaxRows - 1;


da.Update(ds1, "Clients");
MessageBox.Show("Entry Added");


this.Validate();
this.tblClientsBindingSource.EndEdit();
this.tblClientsTableAdapter.Update(this.clientBaseDataSet.tblClients);


}


private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e)
{


}


private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{


}


private void btnUpdate_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
DataRow dRow2 = ds1.Tables["Clients"].Rows[inc];


dRow2[0] = client_IDTextBox.Text;
dRow2[1] = first_NameTextBox.Text;
dRow2[2] = last_NameTextBox.Text;
dRow2[3] = primary_ContactTextBox.Text;
dRow2[4] = secondary_ContactTextBox.Text;
dRow2[5] = date_of_EventTextBox.Text;
dRow2[6] = venueTextBox.Text;
dRow2[7] = number_of_GuestsTextBox.Text;
dRow2[8] = length_of_eventTextBox.Text;
dRow2[9] = equipmentTextBox.Text;
dRow2[10] = priceTextBox.Text;
dRow2[11] = downpaymentTextBox.Text;
dRow2[12] = balanceTextBox.Text;
dRow2[13] = commentsTextBox.Text;


da.Update(ds1, "Clients");
MessageBox.Show("Entry Updated");
}


private void btnDelete_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);


ds1.Tables["Clients"].Rows[inc].Delete();
MaxRows--;
inc = 0;


da.Update(ds1, "Clients");
MessageBox.Show("Record Deleted");


}



}
}

What seems to be the problem here? Or is my way of coding completly wrong?... because this is actually my first attempt at C# :$

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.