PDA

View Full Version : سوال: مشکل این کد از کجاست



Hussein39
دوشنبه 15 فروردین 1390, 19: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)
{
}
}
}

v30sharp
دوشنبه 15 فروردین 1390, 22:29 عصر
سلام
دوست عزيز چند وقته سي شارپ كار ميكني خيلي كد هاتو به هم پيچوندي ميتونستي بسيار راحت تر ور بي دردسر تر باشه كد هات من اصلا از كدهات سر در نياوردم:متفکر::متعجب:

Hussein39
سه شنبه 16 فروردین 1390, 09:16 صبح
عزیز من مبتدی هستم: کداهام رو یکم اصلاح می کنم


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();
}
#endregion

}
}


دیگه فکر کنم راحته فهمیدنش چون خودم باهاش مشکلی ندارم

Hussein39
سه شنبه 16 فروردین 1390, 15:20 عصر
عزیز من مبتدی هستم: کداهام رو یکم اصلاح می کنم


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();
}
#endregion

}
}


دیگه فکر کنم راحته فهمیدنش چون خودم باهاش مشکلی ندارم
کسی نمی دونه مشکلش چیه. اگه میشه یه جواب درست و حسابی بهم بدید اینو می خوام به عنوان پروژه پایانی بدم.:افسرده: