using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace AddrApp
{
public partial class Form1 : Form
{
SqlConnection con= new SqlConnection(@"Data Source=DESKTOP-5KNSK7E\SQLEXPRESS;Initial Catalog=church;Integrated Security=True");
SqlCommand cmd;
SqlDataAdapter adapt;
int ID = 0;
public Form1()
{
InitializeComponent();
DisplayData();
}
}
private void DisplayData()
{
throw new NotImplementedException();
}
private void btn_Insert_Click(object sender, EventArgs e)
{
if (txt_name.Text != "" && txt_address.Text != "" && txt_contact.Text != "" && txt_clergy.Text != "" && txt_cantor.Text != "" && txt_charges.Text != "" && txt_picture.Text != "")
{
cmd = new SqlCommand("insert into church(Name,Address,Contact,Clergy,Cantor,Charges,Picture) values(@Name,@Address,@Contact,@Clergy,@Cantor,@Charges,@Picture)", con);
con.Open();
cmd.Parameters.AddWithValue("@Name", txt_name.Text);
cmd.Parameters.AddWithValue("@Address", txt_address.Text);
cmd.Parameters.AddWithValue("@Contact", txt_contact.Text);
cmd.Parameters.AddWithValue("@Clergy", txt_clergy.Text);
cmd.Parameters.AddWithValue("@Cantor", txt_cantor.Text);
cmd.Parameters.AddWithValue("@Charges", txt_charges.Text);
cmd.Parameters.AddWithValue("@Picture", txt_picture.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Inserted Successfully");
DisplayData();
ClearData();
}
else
{
MessageBox.Show("Please Provide Details!");
}
}
private void DisplayData()
{
con.Open();
DataTable dt=new DataTable();
adapt=new SqlDataAdapter("select * from church",con);
adapt.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
private void ClearData()
{
txt_name.Text = "";
txt_address.Text = "";
txt_contact.Text = "";
txt_clergy.Text = "";
txt_cantor.Text = "";
txt_charges.Text = "";
txt_picture.Text = "";
ID = 0;
}
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
ID = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());
txt_name.Text = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
txt_address.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
txt_contact.Text = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
txt_clergy.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
txt_cantor.Text = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
txt_charges.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
txt_picture.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
}
private void btn_Update_Click(object sender, EventArgs e)
{
if (txt_name.Text != "" && txt_address.Text != "" && txt_contact.Text != "" && txt_clergy.Text != "" && txt_cantor.Text != "" && txt_charges.Text != "" && txt_picture.Text != "")
{
cmd = new SqlCommand("update church set Name=@Name,Address=@Address,Contact=@Contact,Clergy=@Clergy,Cantor=@Cantor,Charges=@Charges,Picture=@Picture where ID=@ID", con);
con.Open();
cmd.Parameters.AddWithValue("@ID", ID);
cmd.Parameters.AddWithValue("@Name", txt_Name.name);
cmd.Parameters.AddWithValue("@Address", txt_address.Text);
cmd.Parameters.AddWithValue("@Contact", txt_contact.Text);
cmd.Parameters.AddWithValue("@Clergy", txt_clergy.Text);
cmd.Parameters.AddWithValue("@Cantor", txt_cantor.Text);
cmd.Parameters.AddWithValue("@Charges", txt_charges.Text);
cmd.Parameters.AddWithValue("@Picture", txt_picture.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Updated Successfully");
con.Close();
DisplayData();
ClearData();
}
else
{
MessageBox.Show("Please Select Record to Update");
}
}
private void btn_Delete_Click(object sender, EventArgs e)
{
if(ID!=0)
{
cmd = new SqlCommand("delete church where ID=@ID",con);
con.Open();
cmd.Parameters.AddWithValue("@ID",ID);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Deleted Successfully!");
DisplayData();
ClearData();
}
else
{
MessageBox.Show("Please Select Record to Delete");
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
What I have tried:
Help, I have tried everything, cant seem to figure it out!!!!!
Error 5 Expected class, delegate, enum, interface, or struct LINE: 27, 30, 33, 37
Error 6 Type or namespace definition, or end-of-file expected LINE: 24,51