03-12-20, 01:41 AM
سلام عليكم حياكم الله عندى كوداضافه الرقم تلقائى وشغال معايا تمام ولكن بعد ما بملاء الحقول واضغط ادخال يشتغل معايا تمام بعدين اضغط 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
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