button2_Click(object sender, EventArgs e)
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data; using System.Data.SqlClient; using System.Data.OleDb; namespace Customer { public partial class frmGridVw : Form { private String connectionString = null; private SqlConnection sqlConnection = null; private SqlDataAdapter sqlDataAdapter = null; private SqlCommandBuilder sqlCommandBuilder = null; private DataTable dataTable = null; private BindingSource bindingSource = null; private String selectQueryString = null; public frmGridVw() { InitializeComponent(); } private void frmGridVw_Load(object sender, EventArgs e) { // GridVw.Columns.Add("gvName" , "name"); //showAllData(); // txtgdvPhoneSearch.Focus(); // GridVw.Enabled = false; Customer.DB.DbCon_call showDb = new Customer.DB.DbCon_call(); try { showDb.con.Open(); //da = new SqlDataAdapter("SELECT CustID as 'Customer ID', CustName as Name,CustPhoneNo as 'Phone No' , CustAddress as Address, CustBloodGroup as 'Blood Group', CustFatherName as 'Father''s Name', CustMotherName as 'Mother''s Name' FROM r_customer", showDb.con); selectQueryString = "SELECT CustID as 'Customer ID', CustName as Name,CustPhoneNo as 'Phone No' , CustAddress as Address, CustBloodGroup as 'Blood Group', CustFatherName as 'Father''s Name', CustMotherName as 'Mother''s Name' FROM r_customer"; sqlDataAdapter = new SqlDataAdapter(selectQueryString, showDb.con); sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter); // ds = new DataSet(); dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); bindingSource = new BindingSource(); bindingSource.DataSource = dataTable; GridVw.DataSource = bindingSource; } catch (Exception ex) { if (showDb.con.State.Equals("Open")) { // showDb.con.Close(); } System.Windows.Forms.MessageBox.Show(ex.Message); } } public void button1_Click(object sender, EventArgs e) { GridVw.Enabled = true; // showAllData(); // searchData(); } //private void GridVw_CellDoubleClick(object sender, DataGridViewCellEventArgs e) //{ // //string str; // //str = GridVw.SelectedCells[0].Value.ToString(); // //textBox1.Text= str; //} public void showAllData() { Customer.DB.DbCon_call showDb = new Customer.DB.DbCon_call(); try { showDb.con.Open(); //da = new SqlDataAdapter("SELECT CustID as 'Customer ID', CustName as Name,CustPhoneNo as 'Phone No' , CustAddress as Address, CustBloodGroup as 'Blood Group', CustFatherName as 'Father''s Name', CustMotherName as 'Mother''s Name' FROM r_customer", showDb.con); selectQueryString = "SELECT CustID as 'Customer ID', CustName as Name,CustPhoneNo as 'Phone No' , CustAddress as Address, CustBloodGroup as 'Blood Group', CustFatherName as 'Father''s Name', CustMotherName as 'Mother''s Name' FROM r_customer"; sqlDataAdapter = new SqlDataAdapter(selectQueryString, showDb.con); sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter); // ds = new DataSet(); dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); bindingSource = new BindingSource(); bindingSource.DataSource = dataTable; GridVw.DataSource = bindingSource; } catch (Exception ex) { if (showDb.con.State.Equals("Open")) { showDb.con.Close(); } System.Windows.Forms.MessageBox.Show(ex.Message); } } public void searchData() { } private void button2_Click(object sender, EventArgs e) { Customer.DB.DbCon_call showDb = new Customer.DB.DbCon_call(); try { showDb.con.Open(); sqlDataAdapter.Update(dataTable); } catch (Exception exceptionObj) { MessageBox.Show(exceptionObj.Message.ToString()); // txtgdvPhoneSearch.Text = exceptionObj.Message; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)