السلام عليكم ورحمة الله وبركاته
ده او موضوع ليا هنا في المنتتدي , وانا لسا جديد في السي شارب وعندي مشكلة وتعبان في حلها ولما صعب علي الأمر فكرت في كتابة كل الكود الموجود في الفورم ورجاء احد يساعدني والمشكلة تقريباً موجودة في كود الأينسرت ... علماً بأني استخدم قاعدة بيانات اكسس وبجدول استخدم حقل BookID وهو نمبر من نوع انتيجر int فما هي المشكلة ...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace _Church_BL3._1._1
{
public partial class frm__AddBook : Form
{
private OleDbConnection myconn;
public frm__AddBook()
{
InitializeComponent();
myconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\mydata.mdb");
}
private void bookdataBindingNavigator_RefreshItems(object sender, EventArgs e)
{
}
private void frm__AddBook_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dataDataSet.booktype' table. You can move, or remove it, as needed.
this.booktypeTableAdapter.Fill(this.dataDataSet.booktype);
// TODO: This line of code loads data into the 'dataDataSet.bookdata' table. You can move, or remove it, as needed.
this.bookdataTableAdapter.Fill(this.dataDataSet.bookdata);
}
private void bindingNavigator1_RefreshItems(object sender, EventArgs e)
{
}
private void button12_Click(object sender, EventArgs e)
{
bookTypeTextBox.Text = comboBox1.Text;
}
private void button6_Click(object sender, EventArgs e)
{
if (bookNameTextBox.Text == string.Empty)
{
MessageBox.Show(" عفواً , برجاء إدخال اسم الكتاب المراد تسجيله .. وشكراً __ ", "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (bookCodeTextBox.Text == string.Empty)
{
MessageBox.Show("عفواً , برجاء إدخال الرقم الكودي للكتاب المراد تسجيله .. وشكراً __ ", "خطاً", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (bookTypeTextBox.Text == string.Empty)
{
MessageBox.Show("عفواً , يرجي تصنيف الكتاب .. اختر من قائمة الأقسام نوع الكتاب ومن ثم اضغط علي مفتاح الأختيار ثم عاود محاولة الحفظ .. وشكراً __ ", "خطاً", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " Select * from bookdata where BookCode = '" + bookCodeTextBox.Text + "' ";
cmd.Connection = myconn;
if (cmd.Connection.State != ConnectionState.Open)
cmd.Connection.Open();
OleDbDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
MessageBox.Show("عفواً , لقد وجدنا كتاب يحمل نفس الرقم الكودي المراد تسجيل الكتاب به يرجي ادخال رقم كودي اخر واعادة المحاولة.. وشكراً __ ", "خطاً", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (bookStateCheckBox1.Checked == false)
{
string message = "وجدنا حالة استعارة و قراءة الكتاب غير مختارة .. فهل تريد ان تجعل هذا الكتاب لا يستخدم في عملية الأستعارة او القراءة ؟ .. إذا لم تكن تود ذلك فعليك اختيار (No) وضع علامة التشيك أمام حالة الكتاب (استعارة أو قراءة) وإعادة المحاولة";
string caption = "تأكيد الحفظ";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
MessageBoxIcon icon = MessageBoxIcon.Question;
MessageBoxDefaultButton defaultbutton = MessageBoxDefaultButton.Button2;
DialogResult result;
result = MessageBox.Show(message, caption, buttons, icon);
if (result == DialogResult.No)
{
return;
}
else
{
MessageBox.Show("هل انت متأكد من حفظ المعلومات؟", "تأكيد الحفظ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
OleDbCommand cmdd = new OleDbCommand();
cmdd.CommandType = CommandType.Text;
cmdd.CommandText = " insert into bookdata(BookID,BookName,BookCode,BookType,BookAuthor,recordDate,BookDesc,BookLocationA,BookLocationB,BookLocationC,BookState,PublishedNo,ISBN,LocalNO,Notes) values(Convert.toint32(bookIDTextBox.Text),'" + bookNameTextBox.Text + "' , '" + bookCodeTextBox.Text + "' , '" + bookTypeTextBox.Text + "', '" + bookAuthorTextBox.Text + "' , '" + recordDateTextBox.Text + "' , '" + bookDescTextBox.Text + "' ,'" + bookLocationATextBox.Text + "' , '" + bookLocationBTextBox.Text + "' , '" + bookLocationCTextBox.Text + "' , '" + bookStateCheckBox1.Checked + "' , '" + publishedNoTextBox.Text + "' , '" + iSBNTextBox + "' , '" + localNOTextBox + "' , '" + notesTextBox + "') ";
cmdd.Connection = myconn;
myconn.Open();
cmdd.ExecuteNonQuery();
myconn.Close();
MessageBox.Show("تم حفظ المعلومات بنجاح", "حفظ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("تم إلغاء الحفظ ", "إلغاء الحفظ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
dr.Close();
dr.Dispose();
cmd.Dispose();
}
}
}
}