بسم الله الرحمن الرحيم
فى البدايه
كل عام وانتم بخير
رمضان كريم
تقبل الله منا ومنكم صالح الاعمال
انا مبتدىء برمجه بلغه سى شارب ودخلت فى جزء الادو
ومعى مشكله فى عمل انسيريت فى قاعده البيانات
الفورم بتشتغل ومافى مشكله بتظهر لى بس رغم كده البيانات مش بتسجل فى قاعده البيانات
ده كود الفورم
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.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
SqlConnection cn ;
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
/*
using ( cn = new SqlConnection())
{
cn.Open();
using ( cmd = new SqlCommand())
{
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from emp";
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
textBox1.Text = dt.Rows[0].Field<string>("name").ToString();
}
}(*/
}
private void Form1_Load(object sender, EventArgs e)
{
using (cn = new SqlConnection())
{
cn.ConnectionString = Properties.Settings.Default.ConString;
cn.Open();
//MessageBox.Show("opened");
using (cmd = new SqlCommand())
{
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select max (country_id) from countries";
try
{
int max = Convert.ToInt32(cmd.ExecuteScalar())+1;
text1.Text = max.ToString();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
using (cn = new SqlConnection())
{
cn.ConnectionString = Properties.Settings.Default.ConString;
cn.Open();
//MessageBox.Show("opened");
using (cmd = new SqlCommand())
{
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
//cmd.CommandText = "insert into countries (country_id,country) values ('"+text1.Text+"','"+text2.Text+"') ";
cmd.CommandText = "INSERT INTO countries (country) values ('" + text2.Text + "') ";
int res = cmd.ExecuteNonQuery();
//if (res > 0)
//{
// MessageBox.Show("done");
//}
//else
//{
// MessageBox.Show("not");
//}
DialogResult ress = MessageBox.Show("تانى ؟","شوف هتعمل ايه " ,MessageBoxButtons.YesNo);
if (ress == DialogResult.Yes)
{
this.Hide();
Form1 frm = new Form1();
frm.ShowDialog();
}
else
{
this.Close();
}
cn.Close();
cn.Dispose();
}
}
}
}
}
وده المشروع بالكامل
