Merhaba iyi günler ben MDI bir form yarattım verileri görüntüleyebilirim ve yahut kategorileri değiştirebilirim ama veriyi kaydettiğim zaman hata veriyor bu hatayı veriyor
Buda hata veren form
Bu benim Veritabanı Kütüphanesi kodları
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; using System.Data; namespace DBLibrary { public class Helper { SqlConnection con; string conString = "Server=.;Database=HomeBook;Trusted_Connection=True;"; DataSet ds; SqlDataAdapter da; SqlCommand cmd; SqlCommandBuilder scb; public Helper() { ds = new DataSet(); con = new SqlConnection(conString); } public DataTable Fill(string sqlCom, string tableName) { da = new SqlDataAdapter(sqlCom, this.con); da.Fill(ds, tableName); return ds.Tables[tableName]; } public DataTable Update(DataTable tbl) { scb = new SqlCommandBuilder(da); da.Update(tbl); return tbl; } } }
Buda form ekleme kodları
using DBLibrary; 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; namespace Kitap_Yurdu { public partial class frmAddProducts : Form { public frmAddProducts() { InitializeComponent(); } Helper h; DataTable tblProducts; DataTable tblCategories; private void frmAddProducts_Load(object sender, EventArgs e) { h = new Helper(); tblProducts = h.Fill("SELECT * FROM Products", "Products"); tblCategories = h.Fill("SELECT * FROM Categories", "Categories"); cmbCategories.ValueMember = "CategoryID"; cmbCategories.DisplayMember = "CategoryName"; cmbCategories.DataSource = tblCategories; } private void btnAdd_Click(object sender, EventArgs e) { DataRow dr = tblProducts.NewRow(); dr["ProductName"] = txtProduct.Text; dr["CategoryID"] = cmbCategories.SelectedValue; dr["StockNumber"] = txtStock.Text; tblProducts.Rows.Add(dr); h.Update(tblProducts); } } }