تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[C#.NET] مشكله عند الضغط على زرار new يظهرلى خطا
#1
سلام عليكم حياكم الله عندى كوداضافه الرقم تلقائى وشغال معايا تمام ولكن بعد ما بملاء الحقول واضغط ادخال يشتغل معايا تمام بعدين اضغط new عشان يمسح كل الحقول ويضيفلى واحد على الرقم اللى عندى يعطينى خطا معلش انا لسه مبتداء  شكرا جزيلا



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 for_my_company.DAL
{
    public partial class ENTER : Form
    {

        DAL.DataAccessLiear log = new DAL.DataAccessLiear();
        SqlConnection con;
       

        public ENTER()
        {
            InitializeComponent();
        }
        
        public void Insert_amrr()
        {
            /// SqlConnection Con = new SqlConnection(@"server=HELLO\AMR1;Database=waterE_DB;Integrated security=true");

            con = log.con;
            con.Open();
            SqlCommand CMD = new SqlCommand();
            CMD.CommandType = CommandType.StoredProcedure;
            CMD.CommandText = "Insert_amr0";
            CMD.Connection = con;

            CMD.Parameters.Add("@id", SqlDbType.Int, 8).Value = textBox1.Text;
            CMD.Parameters.Add("@userr", SqlDbType.NChar).Value = textBox2.Text;
            CMD.Parameters.Add("@passer", SqlDbType.NChar).Value = textBox3.Text;
            CMD.ExecuteNonQuery();
            MessageBox.Show("تمت عملية إضافة السجل للجدول بنجاح", "إضافة سجل", MessageBoxButtons.OK, MessageBoxIcon.Information);
            con.Close();
            con.Dispose();
           
        }

        private void Txt_id_TextChanged(object sender, EventArgs e)
        {
           /// textBox1.Text = GetMaxIDColumn("amr0", "id").ToString();
        }

        private void ENTER_Load(object sender, EventArgs e)
        {
            con = log.con;
            SqlDataAdapter sda = new SqlDataAdapter("Select isnull(max(cast(id as int)),0)+1 from amr0", con);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            textBox1.Text = dt.Rows[0][0].ToString();

             ///Disp();

        }

        private void insert_Click(object sender, EventArgs e)
        {
            Insert_amrr();
        }


        private void button2_Click(object sender, EventArgs e)
        {
           textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox1.Focus();

            con = log.con;
            con.Close();
           SqlDataAdapter sda = new SqlDataAdapter
                ("Select isnull(max(cast(id as int)),0)+1 from amr0", con);
           DataTable dt = new DataTable();
          sda.Fill(dt);
          textBox1.Text = dt.Rows[0][0].ToString();

            this.ActiveControl = textBox2;

            ///Disp();

        }
    }
}

الملف مرفق بصيغه txt


الملفات المرفقة
.txt   ggggg.txt (الحجم : 2.64 ك ب / التحميلات : 2)
الرد }}}
تم الشكر بواسطة:
#2
الاهم من الكود الخطأ ؟ ما الخطأ الذي يظهر
الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم