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 School
{
public partial class Classes : Form
{
SqlCommandBuilder scb;
SqlDataAdapter adapter;
DataSet dataset;
public Classes()
{
InitializeComponent();
}
private void Classes_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'schoolDataSet.Add_Student' table. You can move, or remove it, as needed.
this.add_StudentTableAdapter.Fill(this.schoolDataSet.Add_Student);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string strconnection = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Abbii\Documents\School.mdf;Integrated Security=True;Connect Timeout=30";
SqlConnection connection = new SqlConnection(strconnection);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select Id,F_NIC,Name,Class FROM Add_Student WHERE Class='"+comboBox1.SelectedItem +"'";
cmd.Connection = connection;
DataSet dataset=new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dataset);
dataGridView1.DataSource = dataset.Tables[0];
}
private void button1_Click_1(object sender, EventArgs e)
{
scb = new SqlCommandBuilder(adapter);//nullreference exception was unhandeld.
adapter.Update(dataset);
}
}
}