Hussein39
دوشنبه 15 فروردین 1390, 20:40 عصر
سلام دوستان
من دارم یه سیستم واسه یه مدرسه درست کنم. کدهای سیستم واسه حذف و اضافه و ویرایش و. .. تقریباً با هم مشابه هستند. من یه جدول به اسم Group دارم که شامل سه فیلد G_IDو G_Name و CL_ID_FK هست ولی نمی دونم چرا وقتی می خوام اطلاعات رو تو دیتاست قرار بدم کار نیمه کار تموم می شه یعنی وقتی برنامه رو داشتم تریس می کردم موقعی که اطلاعات رو تو رویداد لود فرم می خواست fill کنه تابع رو نیمه کاره رها می کرد و تمومش می کرد.
کد برنامه:
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 School_Project
{
public partial class Group : Form
{
SqlConnection con;
SqlDataAdapter D_Adoptor;
DataView Dview;
DataSet Dset;
CurrencyManager curManager;
public Group()
{
con = new SqlConnection(Class1.connect("School.mdf"));
D_Adoptor = new SqlDataAdapter("Select * from Group", con);
InitializeComponent();
}
#region Function
void Fill_Dataset()
{
Dset = new DataSet();
D_Adoptor.Fill(Dset, "Group");
D_Adoptor.Update(Dset, "Group");
Dview = new DataView(Dset.Tables["Group"]);
curManager = (CurrencyManager)(this.BindingContext[Dview]);
}
void Binding_TextBox()
{
textBox1.DataBindings.Clear();
textBox2.DataBindings.Clear();
textBox3.DataBindings.Clear();
textBox1.DataBindings.Add("Text", Dview, "G_ID");
textBox2.DataBindings.Add("Text", Dview, "G_Name");
textBox3.DataBindings.Add("Text", Dview, "CL_ID_FK");
curManager = (CurrencyManager)(this.BindingContext[Dview]);
}
void Show_position()
{
label5.Text = (curManager.Position + 1) + " " + curManager.Count;
}
#endregion
#region Event
private void Group_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'schoolDataSet7.Group' table. You can move, or remove it, as needed.
this.groupTableAdapter.Fill(this.schoolDataSet7.Gr oup);
Fill_Dataset();
Binding_TextBox();
Show_position();
}
bool btn = false;
private void button1_Click(object sender, EventArgs e)
{
if (textBox3.Enabled == false)
return;
if (btn == false)
{
button1.Text = ">>";
textBox4.Visible = true;
btn = true;
}
else
{
textBox4.Visible = false;
button1.Text = "<<";
btn = false;
}
}
#endregion
private void btnNext_Click(object sender, EventArgs e)
{
}
}
}
من دارم یه سیستم واسه یه مدرسه درست کنم. کدهای سیستم واسه حذف و اضافه و ویرایش و. .. تقریباً با هم مشابه هستند. من یه جدول به اسم Group دارم که شامل سه فیلد G_IDو G_Name و CL_ID_FK هست ولی نمی دونم چرا وقتی می خوام اطلاعات رو تو دیتاست قرار بدم کار نیمه کار تموم می شه یعنی وقتی برنامه رو داشتم تریس می کردم موقعی که اطلاعات رو تو رویداد لود فرم می خواست fill کنه تابع رو نیمه کاره رها می کرد و تمومش می کرد.
کد برنامه:
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 School_Project
{
public partial class Group : Form
{
SqlConnection con;
SqlDataAdapter D_Adoptor;
DataView Dview;
DataSet Dset;
CurrencyManager curManager;
public Group()
{
con = new SqlConnection(Class1.connect("School.mdf"));
D_Adoptor = new SqlDataAdapter("Select * from Group", con);
InitializeComponent();
}
#region Function
void Fill_Dataset()
{
Dset = new DataSet();
D_Adoptor.Fill(Dset, "Group");
D_Adoptor.Update(Dset, "Group");
Dview = new DataView(Dset.Tables["Group"]);
curManager = (CurrencyManager)(this.BindingContext[Dview]);
}
void Binding_TextBox()
{
textBox1.DataBindings.Clear();
textBox2.DataBindings.Clear();
textBox3.DataBindings.Clear();
textBox1.DataBindings.Add("Text", Dview, "G_ID");
textBox2.DataBindings.Add("Text", Dview, "G_Name");
textBox3.DataBindings.Add("Text", Dview, "CL_ID_FK");
curManager = (CurrencyManager)(this.BindingContext[Dview]);
}
void Show_position()
{
label5.Text = (curManager.Position + 1) + " " + curManager.Count;
}
#endregion
#region Event
private void Group_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'schoolDataSet7.Group' table. You can move, or remove it, as needed.
this.groupTableAdapter.Fill(this.schoolDataSet7.Gr oup);
Fill_Dataset();
Binding_TextBox();
Show_position();
}
bool btn = false;
private void button1_Click(object sender, EventArgs e)
{
if (textBox3.Enabled == false)
return;
if (btn == false)
{
button1.Text = ">>";
textBox4.Visible = true;
btn = true;
}
else
{
textBox4.Visible = false;
button1.Text = "<<";
btn = false;
}
}
#endregion
private void btnNext_Click(object sender, EventArgs e)
{
}
}
}